0

このコードで示されているように、2 つのスタック パネル内にネストされたボタンがあります。

            <StackPanel Grid.Row="1" DataContext="{StaticResource AutomaticUISettings}">
                <StackPanel Orientation="Horizontal">
                    <!--Header-->
                    <Label Content="If Max UI value is met" />

                    <!--Max UI Value Met Help-->
                    <Button Content="[?]" Command="{Binding ShowMaxValueMetHelp}" Margin="5" Foreground="DarkCyan" FontSize="10">
                        <Button.Template>
                            <ControlTemplate TargetType="{x:Type Button}">
                                <ContentPresenter />
                            </ControlTemplate>
                        </Button.Template>
                    </Button>
                </StackPanel>

                <!--Options-->
                <RadioButton GroupName="MeetMaxUI" IsChecked="{Binding Path=Default.MaxMetRadio, Mode=TwoWay, Converter={StaticResource enumBooleanConverter}, ConverterParameter=Stop}" 
                            Command="{x:Static views:SetupAutoUI.CompareSettings}" Content="Stop" Margin="10,0" />
                <RadioButton GroupName="MeetMaxUI" IsChecked="{Binding Path=Default.MaxMetRadio, Mode=TwoWay, Converter={StaticResource enumBooleanConverter}, ConverterParameter=RollOver}" 
                            Command="{x:Static views:SetupAutoUI.CompareSettings}" Content="Roll over to zero" Margin="10,0" />
                <RadioButton GroupName="MeetMaxUI" IsChecked="{Binding Path=Default.MaxMetRadio, Mode=TwoWay, Converter={StaticResource enumBooleanConverter}, ConverterParameter=RollOvertoMin}" 
                            Command="{x:Static views:SetupAutoUI.CompareSettings}" Content="Roll over to Min UI value" Margin="10,0" />
            </StackPanel>

全体が の中GridGroupBoxありUserControlます。[Max UI Value Met Help] ボタンをクリックしても機能しません。これと同様のヘルプ ボタンがGrid上記の a にあり、StackPanel問題なく機能します。これでそれらをコピーして貼り付けようとしましたが、どちらも機能しません。

このボタンが機能しないのはなぜですか?

更新: グリッドに切り替えて、ラベルとボタンをラジオ ボタンのスタックから分離して機能させる必要がありましたが、これが機能しなかった理由を理解したいと思います。

ここのボタンは、残りの UserControl と同じ DataContext にあります。この UserControl 全体に複数のヘルプ ボタンがあり、それらは機能しますが、これは機能しません。どちらを入れても構いません。特定のボタンを別の場所に移動でき、機能します。

なぜそれをしなければならなかったのかを理解せずに何かを修正するのは好きではありません。

新しいコード:

            <!--If Max UI is Met-->
            <StackPanel Orientation="Horizontal" Grid.Row="1">
                <!--Header-->
                <Label Content="If Max UI value is met" />

                <!--Max UI Value Met Help-->
                <Button Content="[?]" Command="{Binding ShowMaxValueMetHelp}" Margin="5" Foreground="DarkCyan" FontSize="10">
                    <Button.Template>
                        <ControlTemplate TargetType="{x:Type Button}">
                            <ContentPresenter />
                        </ControlTemplate>
                    </Button.Template>
                </Button>
            </StackPanel>

            <!--Options-->
            <StackPanel Grid.Row="2"  DataContext="{StaticResource AutomaticUISettings}">
                <RadioButton GroupName="MeetMaxUI" IsChecked="{Binding Path=Default.MaxMetRadio, Mode=TwoWay, Converter={StaticResource enumBooleanConverter}, ConverterParameter=Stop}" 
                        Command="{x:Static views:SetupAutoUI.CompareSettings}" Content="Stop" Margin="10,0" />
                <RadioButton GroupName="MeetMaxUI" IsChecked="{Binding Path=Default.MaxMetRadio, Mode=TwoWay, Converter={StaticResource enumBooleanConverter}, ConverterParameter=RollOver}" 
                        Command="{x:Static views:SetupAutoUI.CompareSettings}" Content="Roll over to zero" Margin="10,0" />
                <RadioButton GroupName="MeetMaxUI" IsChecked="{Binding Path=Default.MaxMetRadio, Mode=TwoWay, Converter={StaticResource enumBooleanConverter}, ConverterParameter=RollOvertoMin}" 
                        Command="{x:Static views:SetupAutoUI.CompareSettings}" Content="Roll over to Min UI value" Margin="10,0" />
            </StackPanel>

グリッドに移動する前のコードは次のようになります。

<UserControl x:Class="BogusProgram.DummyUI"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         xmlns:autoUIsettings="clr-namespace:BogusProgram.Resources"
         xmlns:converters ="clr-namespace:BogusProgram.Converters"
         xmlns:views="clr-namespace:BogusProgram.Views"
         mc:Ignorable="d" >

<!--UserControl Resources-->
<UserControl.Resources>
    <!--Automatic UI Settings-->
    <autoUIsettings:AutoUISettings x:Key="AutomaticUISettings" />

    <!--Enum to Boolean Converter-->
    <converters:EnumBooleanConverter x:Key="enumBooleanConverter" />
</UserControl.Resources>

<!--UserControl Command Bindings-->
<UserControl.CommandBindings>
    <!--Compare Change of all settings to Last set-->
    <CommandBinding Command="{x:Static views:SetupAutoUI.CompareSettings}" Executed="CommandBinding_Executed"/>

    <!--Note: Can use individual RoutedCommands per object-->
    <!--http://stackoverflow.com/questions/254992/how-can-i-best-handle-wpf-radio-buttons-->
</UserControl.CommandBindings>


<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>

    <!--Enable/Disable Automatic UI-->
    <CheckBox Content="Enable Automatic UI" IsChecked="{Binding Source={x:Static autoUIsettings:AutoUISettings.Default}, Path=AutoUIEnabled, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
        Command="{x:Static views:SetupAutoUI.CompareSettings}" x:Name="AutoUICheckbox" Margin="10,5" />

    <!--Automatic UI Settings-->
    <GroupBox Header="Automatic UI Settings" Grid.Row="1" Margin="10,5" 
        IsEnabled="{Binding Source={x:Static autoUIsettings:AutoUISettings.Default}, Path=AutoUIEnabled, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>

            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>

                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>


                <!--Set Automatic UI change by value-->
                <StackPanel Orientation="Horizontal" Margin="10,5">
                    <Label Content="Change UI By:     " />
                    <TextBox Text="{Binding Source={x:Static autoUIsettings:AutoUISettings.Default}, Path=ChangUIby, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" MinWidth="35" x:Name="CHuiBy" 
                        TextChanged="CHuiBy_TextChanged" KeyDown="TextBox_KeyDown" LostFocus="TextBox_LostFocus" />
                </StackPanel>


                <!--Set when to change UI-->
                <StackPanel Orientation="Horizontal" Grid.Row="1" Margin="10,5">
                    <Label Content="Change UI Every:" />
                    <TextBox Text="{Binding Source={x:Static autoUIsettings:AutoUISettings.Default}, Path=WaitPeriod, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" MinWidth="35" x:Name="CHuiEv"
                        TextChanged="CHuiEv_TextChanged" KeyDown="TextBox_KeyDown" LostFocus="TextBox_LostFocus" />

                    <!--Change UI Every Help-->
                    <Button Content="[?]" Command="{Binding ShowCHuiEvHelp}" Margin="5" Foreground="DarkCyan" FontSize="10">
                        <Button.Template>
                            <ControlTemplate TargetType="{x:Type Button}">
                                <ContentPresenter />
                            </ControlTemplate>
                        </Button.Template>
                    </Button>
                </StackPanel>


                <!--Change UI for-->
                <StackPanel Orientation="Horizontal" Grid.Row="2" Margin="10,5" IsEnabled="{Binding Source={x:Static autoUIsettings:AutoUISettings.Default}, Path=RunPeriodEnabled, Mode=TwoWay, 
                    UpdateSourceTrigger=PropertyChanged}">

                    <Label Content="Change UI For:   " />
                    <TextBox Text="{Binding Source={x:Static autoUIsettings:AutoUISettings.Default}, Path=RunPeriod, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" MinWidth="35" x:Name="RunFor"
                        TextChanged="RunFor_TextChanged" KeyDown="TextBox_KeyDown" LostFocus="TextBox_LostFocus" />

                    <!--Change UI For Help-->
                    <Button Content="[?]" Command="{Binding ShowCHuiForHelp}" Margin="5" Foreground="DarkCyan" FontSize="10">
                        <Button.Template>
                            <ControlTemplate TargetType="{x:Type Button}">
                                <ContentPresenter />
                            </ControlTemplate>
                        </Button.Template>
                    </Button>
                </StackPanel>


                <!--Set Max UI value-->
                <StackPanel Orientation="Horizontal" Grid.Column="1" Margin="10,5">
                    <Label Content="Max UI Value:" />
                    <TextBox Text="{Binding Source={x:Static autoUIsettings:AutoUISettings.Default}, Path=MaxUI, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" MinWidth="35" x:Name="MaxUI" 
                        TextChanged="MaxUI_TextChanged" KeyDown="TextBox_KeyDown" LostFocus="TextBox_LostFocus" />

                    <!--Max UI Value Help-->
                    <Button Content="[?]" Command="{Binding ShowMaxValueHelp}" Margin="5" Foreground="DarkCyan" FontSize="10">
                        <Button.Template>
                            <ControlTemplate TargetType="{x:Type Button}">
                                <ContentPresenter />
                            </ControlTemplate>
                        </Button.Template>
                    </Button>
                </StackPanel>


                <!--Set Min UI value-->
                <StackPanel Orientation="Horizontal" Grid.Column="1" Grid.Row="1" Margin="10,5">
                    <Label Content="Min UI Value:" />
                    <TextBox Text="{Binding Source={x:Static autoUIsettings:AutoUISettings.Default}, Path=MinUI, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" MinWidth="35" x:Name="MinUI" 
                        TextChanged="MinUI_TextChanged" KeyDown="TextBox_KeyDown" LostFocus="TextBox_LostFocus" />

                    <!--Min UI Value Help-->
                    <Button Content="[?]" Command="{Binding ShowMinValueHelp}" Margin="5" Foreground="DarkCyan" FontSize="10">
                        <Button.Template>
                            <ControlTemplate TargetType="{x:Type Button}">
                                <ContentPresenter />
                            </ControlTemplate>
                        </Button.Template>
                    </Button>
                </StackPanel>


                <!--Enable/Disable Max Run Period-->
                <CheckBox Content="Enable Max Run Period" IsChecked="{Binding Source={x:Static autoUIsettings:AutoUISettings.Default}, Path=RunPeriodEnabled, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
                    Command="{x:Static views:SetupAutoUI.CompareSettings}" x:Name="RunPeriodCheckbox" Margin="10" Grid.Column="1" Grid.Row="2"/>
            </Grid>


            <!--If Max UI is Met-->
            <StackPanel Grid.Row="1" DataContext="{StaticResource AutomaticUISettings}">
                <StackPanel Orientation="Horizontal">
                    <!--Header-->
                    <Label Content="If Max UI value is met" />

                    <!--Max UI Value Met Help-->
                    <Button Content="[?]" Command="{Binding ShowMaxValueMetHelp}" Margin="5" Foreground="DarkCyan" FontSize="10">
                        <Button.Template>
                            <ControlTemplate TargetType="{x:Type Button}">
                                <ContentPresenter />
                            </ControlTemplate>
                        </Button.Template>
                    </Button>
                </StackPanel>

                <!--Options-->
                <RadioButton GroupName="MeetMaxUI" IsChecked="{Binding Path=Default.MaxMetRadio, Mode=TwoWay, Converter={StaticResource enumBooleanConverter}, ConverterParameter=Stop}" 
                            Command="{x:Static views:SetupAutoUI.CompareSettings}" Content="Stop" Margin="10,0" />
                <RadioButton GroupName="MeetMaxUI" IsChecked="{Binding Path=Default.MaxMetRadio, Mode=TwoWay, Converter={StaticResource enumBooleanConverter}, ConverterParameter=RollOver}" 
                            Command="{x:Static views:SetupAutoUI.CompareSettings}" Content="Roll over to zero" Margin="10,0" />
                <RadioButton GroupName="MeetMaxUI" IsChecked="{Binding Path=Default.MaxMetRadio, Mode=TwoWay, Converter={StaticResource enumBooleanConverter}, ConverterParameter=RollOvertoMin}" 
                            Command="{x:Static views:SetupAutoUI.CompareSettings}" Content="Roll over to Min UI value" Margin="10,0" />
            </StackPanel>


            <!--If Min UI is Met-->
            <StackPanel Grid.Row="2" DataContext="{StaticResource AutomaticUISettings}">
                <StackPanel Orientation="Horizontal">
                    <!--Header-->
                    <Label Content="If Min UI value is met" />

                    <!--Min UI Value Met Help-->
                    <Button Content="[?]" Command="{Binding ShowMinValueMetHelp}" Margin="5" Foreground="DarkCyan" FontSize="10">
                        <Button.Template>
                            <ControlTemplate TargetType="{x:Type Button}">
                                <ContentPresenter />
                            </ControlTemplate>
                        </Button.Template>
                    </Button>
                </StackPanel>

                <!--Options-->
                <RadioButton GroupName="MeetMinUI" IsChecked="{Binding Path=Default.MinMetRadio, Mode=TwoWay, Converter={StaticResource enumBooleanConverter}, ConverterParameter=Stop}"
                        Command="{x:Static views:SetupAutoUI.CompareSettings}" Content="Stop" Margin="10,0" />
                <RadioButton GroupName="MeetMinUI" IsChecked="{Binding Path=Default.MinMetRadio, Mode=TwoWay, Converter={StaticResource enumBooleanConverter}, ConverterParameter=RollOver}" 
                        Command="{x:Static views:SetupAutoUI.CompareSettings}" Content="Roll over to 255" Margin="10,0" />
                <RadioButton GroupName="MeetMinUI" IsChecked="{Binding Path=Default.MinMetRadio, Mode=TwoWay, Converter={StaticResource enumBooleanConverter}, ConverterParameter=RollOvertoMax}" 
                        Command="{x:Static views:SetupAutoUI.CompareSettings}" Content="Roll over to Max UI value" Margin="10,0" />
                <RadioButton GroupName="MeetMinUI" IsChecked="{Binding Path=Default.MinMetRadio, Mode=TwoWay, Converter={StaticResource enumBooleanConverter}, ConverterParameter=RolltoValue}" 
                        Command="{x:Static views:SetupAutoUI.CompareSettings}" Content="Roll over to calculated Value" Margin="10,0" />
                <RadioButton GroupName="MeetMinUI" IsChecked="{Binding Path=Default.MinMetRadio, Mode=TwoWay, Converter={StaticResource enumBooleanConverter}, ConverterParameter=InvertUI}" 
                        Command="{x:Static views:SetupAutoUI.CompareSettings}" Content="Change UI in inverse direction" Margin="10,0" />
            </StackPanel>

            <!--Max Run Period-->
            <StackPanel Grid.Row="3" IsEnabled="{Binding Source={x:Static autoUIsettings:AutoUISettings.Default}, Path=RunPeriodEnabled, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                DataContext="{StaticResource AutomaticUISettings}">

                <!--Header-->
                <Label Content="If Run Period is met" />

                <!--Options-->
                <RadioButton GroupName="MeetRunPeriod" IsChecked="{Binding Path=Default.RunPeriodRadio, Mode=TwoWay, Converter={StaticResource enumBooleanConverter}, ConverterParameter=Stop}" 
                        Command="{x:Static views:SetupAutoUI.CompareSettings}" Content="Stop" Margin="10,0" />
                <RadioButton GroupName="MeetRunPeriod" IsChecked="{Binding Path=Default.RunPeriodRadio, Mode=TwoWay, Converter={StaticResource enumBooleanConverter}, ConverterParameter=Run}" 
                        Command="{x:Static views:SetupAutoUI.CompareSettings}" Content="Continue to running at last UI" Margin="10,0" />
            </StackPanel>
        </Grid>
    </GroupBox>

    <StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right">
        <Button Content="Apply" Command="{Binding ApplyAutoUI}" Padding="5" Margin="10,0" IsEnabled="{Binding AutoUIChanged}" />
        <Button Content="Close/Cancel" Command="{Binding CloseAutoUI}" Padding="5" Margin="10,0" />
    </StackPanel>
</Grid>

4

1 に答える 1