C# MaterialDesignXamlToolkit wpf对话框主机按钮在打开时被禁用
我正在使用MaterialDesignThemes nuget包和Mahapps.Metro包 我有这个对话主持人C# MaterialDesignXamlToolkit wpf对话框主机按钮在打开时被禁用,c#,wpf,xaml,material-design,mahapps.metro,C#,Wpf,Xaml,Material Design,Mahapps.metro,我正在使用MaterialDesignThemes nuget包和Mahapps.Metro包 我有这个对话主持人 <material:DialogHost Name="PopupAddCustom" HorizontalAlignment="Center" VerticalAlignment="Center" IsOpen="False" > <material:DialogHost.DialogContent> <StackPanel M
<material:DialogHost Name="PopupAddCustom" HorizontalAlignment="Center" VerticalAlignment="Center" IsOpen="False" >
<material:DialogHost.DialogContent>
<StackPanel Margin="16" Orientation="Vertical">
<Label Content="Add custom date" FontSize="16" />
<DatePicker />
<StackPanel Orientation="Horizontal">
<Button Content="ACCEPT" Style="{DynamicResource MaterialDesignFlatButton}" IsDefault="True" Margin="0,8,8,0" Command="material:DialogHost.CloseDialogCommand" CommandParameter="True" />
<Button Content="CANCEL" Style="{DynamicResource MaterialDesignFlatButton}" IsCancel="True" Margin="0,8,8,0" Command="material:DialogHost.CloseDialogCommand" CommandParameter="False" />
</StackPanel>
</StackPanel>
</material:DialogHost.DialogContent>
</material:DialogHost>
当我像这样打开对话框时,按钮处于正常工作状态,我是否遗漏了一些明显的内容?通过为这样的按钮设置命令目标,问题得到了解决
this.Loaded += delegate(object sender, RoutedEventArgs args)
{
this.PopupAddCustom.IsOpen = true;
};
CommandTarget="{Binding ElementName=PopupAddCustom}"
为了节省别人的时间:我将对话框内容指定为命令参数,而指定
CommandTarget
对我没有帮助
在我的例子中,将CommandParameter
放在Command
之前是有帮助的
您可以通过将内容作为资源传递来实现这一点
例子:
之前:
**对话内容**
**按钮内容**
之后:
**对话内容**
**按钮内容**
对话框主机按钮不再被禁用
CommandTarget="{Binding ElementName=PopupAddCustom}"
<Button
...
Command="{x:Static material:DialogHost.OpenDialogCommand}"
>
<Button.CommandParameter>
<Grid>
** Dialog content **
</Grid>
</Button.CommandParameter>
** Button content **
</Button>
<UserControl.Resources>
<Grid x:Key="MyDialogContent">
** Dialog content **
</Grid>
</UserControl.Resources>
<Button
...
CommandParameter="{StaticResource MyDialogContent}"
Command="{x:Static material:DialogHost.OpenDialogCommand}"
>
** Button content **
</Button>