绑定UserControls属性

时间:2013-01-03 23:51:01

标签: c# wpf xaml user-controls opacity

我有点奇怪的atm。

我想要做的第一件事是将我的usercontrol的不透明度绑定到带有转换器的布尔属性。我在一个全屏WPF应用程序与一个小菜单。如果菜单打开,其他任何东西都应该得到较低的不透明度。有点灰了一切。

第二件事是菜单不应该从usercontrol继承不透明度。

不知道我可以谷歌。我努力寻找有用的东西是徒劳的。 希望你能帮帮我。

Greets Lucas

查看:

<UserControl ....>
...

    <view:InvisibleButtonView Grid.Row="0" Grid.Column="2" 
                            Height="75" Width="75"
                            VerticalAlignment="Top" HorizontalAlignment="Right" />

    <view:IdleScreenView Visibility="{Binding IsWelcomeScreenActive,Converter={StaticResource ResourceKey=NegativeBooleanToVisibilityConverter}}" 
                       Grid.Row="0" Grid.RowSpan="2" Grid.Column="1" 
                       VerticalAlignment="Center"/>

    <view:WelcomeScreenView Visibility="{Binding IsWelcomeScreenActive,Converter={StaticResource ResourceKey=BooleanToVisibilityConverter}}" 
                          Grid.Row="0" Grid.RowSpan="2" Grid.Column="1" 
                          VerticalAlignment="Center"/>

    <view:DateView Grid.Row="2" Grid.Column="1" 
                 VerticalAlignment="Center" />

    <view:InvisibleInputView Height="25" Width="100" Background="Transparent" BorderBrush="Transparent" Cursor=""/>

    <view:MainMenuView Grid.RowSpan="3" Grid.ColumnSpan="3" Visibility="{Binding IsAnyMenuActive, Converter={StaticResource ResourceKey=BooleanToVisibilityConverter}}" 
                         Height="300" Width="250" />

</Grid>

1 个答案:

答案 0 :(得分:2)

以背景视图帮助我

<UserControl.Resources>
    <SolidColorBrush x:Key="MenuActiveBackgroundColor" Color="Green"/>
    <SolidColorBrush x:Key="MenuInactiveBackgroundColor" Color="Tomato"/>
</UserControl.Resources>

<Grid>
    <Grid.Style>
        <Style>
            <Style.Triggers>
                <DataTrigger Binding="{Binding AnyMenuIsActive}" Value="true">
                    <Setter Property="Grid.Background" Value="{DynamicResource MenuActiveBackgroundColor}"/>
                </DataTrigger>
                <DataTrigger Binding="{Binding AnyMenuIsActive}" Value="false">
                    <Setter Property="Grid.Background" Value="{DynamicResource MenuInactiveBackgroundColor}"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Grid.Style>
</Grid>