79201726

Date: 2024-11-19 00:03:19
Score: 0.5
Natty:
Report link

Can we close this issue? You already received correct comments helping you to deal with your if blocks. And I'll add something completely different: the interest here is not to touch any code-behind, View Model, and no code at all. After all, what you want are mere decorative details. It would be not nice to contaminate code with them.

Let's try to implement it in pure XAML:

    <Window x:Class="SA.View.WindowMain"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="WindowMain" Height="450" Width="800">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Border BorderBrush="Black" BorderThickness="1"
                Padding="10 4 10 4">
            <TextBlock>Command bar</TextBlock>
            <Border.Style>
                <Style TargetType="Border">
                    <Style.Triggers>
                        <DataTrigger
                            Binding="{Binding WindowState,
                            RelativeSource=
                            {RelativeSource AncestorType=Window}}"
                            Value="Maximized">
                                <Setter Property="CornerRadius" Value="0"/>
                                <Setter Property="Margin" Value="0 0 0 4"/>
                        </DataTrigger>
                        <DataTrigger Binding="{Binding WindowState,
                            RelativeSource=
                            {RelativeSource AncestorType=Window}}"
                            Value="Normal">
                                <Setter Property="CornerRadius" Value="9"/>
                                <Setter Property="Margin" Value="8 4 8 4"/>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </Border.Style>
        </Border>
    </Grid>
</Window>

Here, RelativeSource binding is used to handle property changed events from the parent Window recognized by its type. I also added another Setter to both data triggers to change the bar border margins, to make it look nicer when the corners get rounded.

I hope you don't want to change also the bar visibility any longer, but if you want, you don't need any setters in the data triggers except

<Setter Property="Visibility" Value="Collapsed"/>
<!-- ... -->
<!-- and -->
<Setter Property="Visibility" Value="Visible"/>

This way, you could change the bar visibility depending on the window state, and border radius and other properties could be static because you don't need to change them if the element is invisible.

Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Starts with a question (0.5): Can we
  • Low reputation (1):
Posted by: Sergey A Kryukov