按钮已禁用 - DialogHost 和日历

因此,出于某种原因,我无法启用该按钮。我在选择器用户控件(MaterialDesignInXamlToolkit)中使用倒数第二个示例 - https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit/blob/master/MainDemo.Wpf/Pickers.xaml

http://img1.mukewang.com/61a373870001b9fc12790639.jpg

根据所附图片,这是我在运行以下代码(原始)时看到的内容:


<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>


至尊宝的传说
浏览 349回答 1
1回答

斯蒂芬大帝

您没有设置CommandTarget属性,Button这就是未启用它的原因。<Button Margin="8 0 0 0" Content="..."&nbsp; &nbsp; &nbsp; &nbsp; IsEnabled="True"&nbsp; &nbsp; &nbsp; &nbsp; Command="{x:Static materialDesign:DialogHost.OpenDialogCommand}"&nbsp; &nbsp; &nbsp; &nbsp; CommandTarget="{Binding ElementName=PopupAddCustom}"></Button><materialDesign:DialogHost Name="PopupAddCustom" HorizontalAlignment="Center" VerticalAlignment="Center" IsOpen="False"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; materialDesign:DialogHost.DialogOpenedCallback="CalendarDialogOpenedEventHandler"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; materialDesign:DialogHost.DialogClosingCallback="CalendarDialogClosingEventHandler">&nbsp; &nbsp; <materialDesign:DialogHost.DialogContent>&nbsp; &nbsp; &nbsp; &nbsp; <Grid>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <Grid.RowDefinitions>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <RowDefinition Height="Auto" />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <RowDefinition Height="Auto" />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </Grid.RowDefinitions>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <Calendar x:Name="Calendar" Margin="-1 -4 -1 0" />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <StackPanel Grid.Row="1" Margin="8" HorizontalAlignment="Right" Orientation="Horizontal">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <Button Command="{x:Static materialDesign:DialogHost.CloseDialogCommand}" IsDefault="True"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CommandParameter="1" Style="{DynamicResource MaterialDesignFlatButton}">OK</Button>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <Button Command="{x:Static materialDesign:DialogHost.CloseDialogCommand}" IsCancel="True"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CommandParameter="0" Style="{DynamicResource MaterialDesignFlatButton}">CANCEL</Button>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </StackPanel>&nbsp; &nbsp; &nbsp; &nbsp; </Grid>&nbsp; &nbsp; </materialDesign:DialogHost.DialogContent></materialDesign:DialogHost>
打开App,查看更多内容
随时随地看视频慕课网APP