Aşağıda, WPF'te bir WrapPanel içerisinde bulunan iki buton için istenen işlevleri yerine getirecek bir XAML örneği ve ardından gerekli C# kod örnekleri verilmiştir. Bu örnekte birinci butonun (OtherAppsButton) bir web sitesini açması, ikinci butonun (DonateButton) ise sağ tıklandığında context menu (sağ tıklama menüsü) açılması sağlanmıştır:
XAML:
<WrapPanel Grid.Row="1" Margin="0,8,0,0" HorizontalAlignment="Left">
<!-- Other Apps Butonu -->
<Button x:Name="OtherAppsButton" Content="Other Apps" Width="210" Click="OtherAppsButton_Click"/>
<!-- Donate Butonu ve Context Menu -->
<Button x:Name="DonateButton" Content="Donate" Width="210" Margin="8,0,0,0" MouseRightButtonDown="DonateButton_MouseRightButtonDown">
<Button.ContextMenu>
<ContextMenu>
<MenuItem Header="IBAN" Click="IBAN_Click"/>
<MenuItem Header="BuyMeACoffee" Click="BuyMeACoffee_Click"/>
</ContextMenu>
</Button.ContextMenu>
</Button>
</WrapPanel>
C# Code-behind:
using System.Diagnostics;
using System.Windows;
using System.Windows.Input;
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void OtherAppsButton_Click(object sender, RoutedEventArgs e)
{
// Örnek bir web sitesine yönlendirme
Process.Start(new ProcessStartInfo
{
FileName = "http://example.com",
UseShellExecute = true
});
}
private void DonateButton_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
// Butonun context menüsünü göster
DonateButton.ContextMenu.IsOpen = true;
}
private void IBAN_Click(object sender, RoutedEventArgs e)
{
// IBAN bilgilerini Message Box ile gösterme ve pano'ya kopyalama
string iban = "TR00 0000 0000 0000 0000 0000 00"; // Gerçek IBAN numaranızı buraya girin
string fullName = "Adınız Soyadınız"; // Gerçek adınızı buraya girin
Clipboard.SetText(iban);
MessageBox.Show(fullName + "\nIBAN: " + iban, "IBAN Information", MessageBoxButton.OK, MessageBoxImage.Information);
}
private void BuyMeACoffee_Click(object sender, RoutedEventArgs e)
{
// BuyMeACoffee web sitesine yönlendirme
Process.Start(new ProcessStartInfo
{
FileName = "https://www.buymeacoffee.com/example",
UseShellExecute = true
});
}
}
Bu C# örneğinde, Process.Start metodu, kullanıcının sistemdeki varsayılan web tarayıcısı üzerinden belirtilen adreslere yönlendirmek için kullanılır. UseShellExecute = true ile url'lerin tarayıcıda açılması sağlanır.
Context menu (sağ tıklama menüsü) için ContextMenu öğesinin içinde MenuItem öğeleri eklenmiştir. Her bir MenuItem için bir Click olayı tanımlanmış ve bu olaylar C# kodları içinde ele alınmıştır.
Clipboard.SetText metodu, verilen metni sistem panosuna kopyalar. MessageBox.Show fonksiyonu ise bir ileti kutusu görüntüler.
Lütfen dikkat edin: ProcessStartInfo ve Clipboard sınıflarını kullanabilmek için System.Diagnostics ve System.Windows ad alanlarını projenize dahil etmelisiniz.
Bu kodları kendi projenize entegre etmeden önce, kendi web sitelerinizin adreslerini ve kişisel bilgilerinizi uygun yerlere eklemeyi unutmayın. Ayrıca, uygulamanın çalışabilmesi için kullanıcının sisteminde varsayılan web tarayıcısının düzgün bir şekilde yapılandırılmış olması gerekmektedir.