IsEnabled StackPanel snap button has children

I am wondering if I can associate my Button isEnabled with my StackPanel children (have children). If there are children on the stack, then my button is on, there are no children, my button is disabled. I am currently just processing this in code, but I started wondering if this could be related. Thanks for any thoughts ...

+3
source share
3 answers

In fact, since you are dealing with bool, you can invert the logic and do it without converters:

<StackPanel Name="sp" />
<Button Content="A Button">
    <Button.Style>
        <Style TargetType="{x:Type Button}">
            <Style.Triggers>
                <DataTrigger Binding="{Binding ElementName=sp, Path=Children.Count}" Value="0">
                    <Setter Property="IsEnabled" Value="False"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Button.Style>
</Button>

, , Children.Count DP, ItemsControl, ( - StackPanel):

<ItemsControl Name="ic" />
<Button Content="A Button">
    <Button.Style>
        <Style TargetType="{x:Type Button}">
            <Style.Triggers>
                <DataTrigger Binding="{Binding ElementName=ic, Path=Items.Count}" Value="0">
                    <Setter Property="IsEnabled" Value="False"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Button.Style>
</Button>
+6

ValueConverter, . IsEnabled Button StackPanel , - , true/false.

+2

( ItemsPanel), H.B. ActualHeight StackPanel, 0, .

<Style.Triggers>
  <DataTrigger Binding="{Binding ElementName=sp, Path=ActualHeight}" Value="0">
    <Setter Property="IsEnabled" Value="False"/>
  </DataTrigger>
</Style.Triggers>

, VerticalAlignment="Top" StackPanel, .

0

All Articles