Как передать строку из класса данных в ContentDialog
В этом сценарии вы можете привязать свойство MoreButton
Command
и передать текущее DataContext
в качестве параметра метода с CommandParameter
.
Например.
public MainPage()
{
this.InitializeComponent();
this.DataContext = this;
Emails = MyEmailManager.GetEmails();
}
public ICommand OpenDialog
{
get
{
return new CommadEventHandler<Email>((s) => OpenDialogCommandFun(s));
}
}
private async void OpenDialogCommandFun(Email s)
{
ContentDialog dialogServiceUpdates = new ContentDialog
{
Title = s.From,
Content = s.Body,
CloseButtonText = "OK"
};
ContentDialogResult result = await dialogServiceUpdates.ShowAsync();
}
Xaml
<Button
x:Name="MoreBtn"
Grid.Column="1"
Margin="10"
Padding="10"
HorizontalAlignment="Right"
VerticalAlignment="Top"
Background="Transparent"
Command="{Binding ElementName=RootGrid, Path=DataContext.OpenDialog}"
CommandParameter="{Binding}"
Content=""
FontFamily="Segoe MDL2 Assets"
Visibility="{Binding ShowButton, Converter={StaticResource MyConveter}}"
/>
Для лучшего понимания я загрузил пример кода здесь , проверьте его.