因此由于某种原因,我无法启用该按钮。我正在Pickers用户控件(MaterialDesignInXamlToolkit中使用倒数第二个示例 )-https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit/blob/master/MainDemo.Wpf/Pickers.xaml
<StackPanel Orientation="Horizontal" Margin="0 25 0 15" HorizontalAlignment="Center" IsEnabled="True">
<TextBlock Foreground="{DynamicResource MaterialDesignBodyLight}" Text="{Binding Date, StringFormat=d}" VerticalAlignment="Center" FontSize="24" />
<Button Margin="8 0 0 0" Content="..."
IsEnabled="True"
materialDesign:DialogHost.DialogOpenedAttached="CalendarDialogOpenedEventHandler"
materialDesign:DialogHost.DialogClosingAttached="CalendarDialogClosingEventHandler"
Command="{x:Static materialDesign:DialogHost.OpenDialogCommand}">
<Button.CommandParameter>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Calendar x:Name="Calendar" Margin="-1 -4 -1 0" />
<StackPanel Grid.Row="1" Margin="8" HorizontalAlignment="Right" Orientation="Horizontal">
<Button Command="{x:Static materialDesign:DialogHost.CloseDialogCommand}" IsDefault="True" CommandParameter="1" Style="{DynamicResource MaterialDesignFlatButton}">OK</Button>
<Button Command="{x:Static materialDesign:DialogHost.CloseDialogCommand}" IsCancel="True" CommandParameter="0" Style="{DynamicResource MaterialDesignFlatButton}">CANCEL</Button>
</StackPanel>
</Grid>
</Button.CommandParameter>
</Button>
我确实看过这篇类似的文章,但没有获奖-MaterialDesignXamlToolkit wpf dialoghost buttons are disabled when opened
xaml.cs:
public void CalendarDialogOpenedEventHandler(object sender, DialogOpenedEventArgs eventArgs)
{
Calendar.SelectedDate = ((ClientIntroViewModel)DataContext).Date;
}
public void CalendarDialogClosingEventHandler(object sender, DialogClosingEventArgs eventArgs)
{
if (!Equals(eventArgs.Parameter, "1")) return;
if (!Calendar.SelectedDate.HasValue)
{
eventArgs.Cancel();
return;
}
((ClientIntroViewModel)DataContext).Date = Calendar.SelectedDate.Value;
}
最新的XAML:
<StackPanel Orientation="Horizontal" Margin="0 25 0 0" HorizontalAlignment="Center" IsEnabled="True">
<Label Foreground="{DynamicResource MaterialDesignBodyLight}" VerticalAlignment="Center" Margin="0,0,5,0">Birth Date:</Label>
<TextBlock Foreground="{DynamicResource MaterialDesignBodyLight}" Text="{Binding Date, StringFormat=d}" VerticalAlignment="Center" FontSize="24" />
<Button Margin="8 0 0 0" Content="..."
IsEnabled="True"
materialDesign:DialogHost.DialogOpenedAttached="CalendarDialogOpenedEventHandler"
materialDesign:DialogHost.DialogClosingAttached="CalendarDialogClosingEventHandler"
Command="{x:Static materialDesign:DialogHost.OpenDialogCommand}"
CommandTarget="{Binding ElementName=PopupAddCustom}">
</Button>
<materialDesign:DialogHost Name="PopupAddCustom" HorizontalAlignment="Center" VerticalAlignment="Center" IsOpen="False" >
<materialDesign:DialogHost.DialogContent>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Calendar x:Name="Calendar" Margin="-1 -4 -1 0" />
<StackPanel Grid.Row="1" Margin="8" HorizontalAlignment="Right" Orientation="Horizontal">
<Button Command="{x:Static materialDesign:DialogHost.CloseDialogCommand}" IsDefault="True"
CommandParameter="1" Style="{DynamicResource MaterialDesignFlatButton}">OK</Button>
<Button Command="{x:Static materialDesign:DialogHost.CloseDialogCommand}" IsCancel="True"
CommandParameter="0" Style="{DynamicResource MaterialDesignFlatButton}">CANCEL</Button>
</StackPanel>
</Grid>
</materialDesign:DialogHost.DialogContent>
</materialDesign:DialogHost>
</StackPanel>
答案 0 :(得分:1)
您没有在CommandTarget
上设置Button
属性,因此未启用该属性。
<Button Margin="8 0 0 0" Content="..."
IsEnabled="True"
Command="{x:Static materialDesign:DialogHost.OpenDialogCommand}"
CommandTarget="{Binding ElementName=PopupAddCustom}">
</Button>
<materialDesign:DialogHost Name="PopupAddCustom" HorizontalAlignment="Center" VerticalAlignment="Center" IsOpen="False"
materialDesign:DialogHost.DialogOpenedCallback="CalendarDialogOpenedEventHandler"
materialDesign:DialogHost.DialogClosingCallback="CalendarDialogClosingEventHandler">
<materialDesign:DialogHost.DialogContent>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Calendar x:Name="Calendar" Margin="-1 -4 -1 0" />
<StackPanel Grid.Row="1" Margin="8" HorizontalAlignment="Right" Orientation="Horizontal">
<Button Command="{x:Static materialDesign:DialogHost.CloseDialogCommand}" IsDefault="True"
CommandParameter="1" Style="{DynamicResource MaterialDesignFlatButton}">OK</Button>
<Button Command="{x:Static materialDesign:DialogHost.CloseDialogCommand}" IsCancel="True"
CommandParameter="0" Style="{DynamicResource MaterialDesignFlatButton}">CANCEL</Button>
</StackPanel>
</Grid>
</materialDesign:DialogHost.DialogContent>
</materialDesign:DialogHost>