У меня есть кнопка в MainPage, для которой я хочу выполнить метод, который существует в другом классе (Shelf.cs)
Я пытался сделать click = "local: Button_click" (local = using: Shelf),он не позволил мне и продолжал хотеть добавить «новый обработчик событий»
Кнопка в MainPage.xaml:
<Button x:Name="AddBookButton" Width="150" Height="150" Margin="675,0,0,0" click="Button_click"> // this creates a new method inside MainPage
метод в Shelf.cs:
public async void Button_Click(object sender, RoutedEventArgs e)
{
StackPanel adddialog = new StackPanel
{
Orientation = Orientation.Horizontal,
Width = 484,
FlowDirection = FlowDirection.RightToLeft
};
TextBox title = new TextBox
{
Header = "العنوان:",
PlaceholderText = "عنوان الكتاب",
Width = 156,
Margin = new Thickness(0, 0, 8, 0),
FlowDirection = FlowDirection.RightToLeft
};
TextBox author = new TextBox
{
Header = "المؤلف:",
PlaceholderText = "مؤلف الكتاب",
Width = 156,
Margin = new Thickness(0, 0, 8, 0),
FlowDirection = FlowDirection.RightToLeft
};
TextBox publisher = new TextBox
{
Header = "الناشر (اختياري):",
PlaceholderText = "ناشر الكتاب",
Width = 156,
Margin = new Thickness(0, 0, 0, 0),
FlowDirection = FlowDirection.RightToLeft
};
adddialog.Children.Insert(0, title);
adddialog.Children.Insert(1, author);
adddialog.Children.Insert(2, publisher);
ContentDialog addFileDialog = new ContentDialog
{
Title = "أضف بيانات الكتاب الجديد",
Content = adddialog,
PrimaryButtonText = "إضافة",
CloseButtonText = "إلغاء",
FlowDirection = FlowDirection.RightToLeft,
Width = 700
};
ContentDialogResult result = await addFileDialog.ShowAsync();
if (result == ContentDialogResult.Primary)
{
Book book = new Book()
{
Title = title.Text,
Author = author.Text,
};
try
{
book.Publisher = publisher.Text;
}
catch { }
Books.Add(book);
AddBookButton.Visibility = Visibility.Collapsed;
}
}
}
Как мне сделать так, чтобы он шел к методу в shelf.cs?или, возможно, направить туда событие?