WPF图像能见度XAML绑定 [英] WPF Image Visibility Binding in XAML

查看:153
本文介绍了WPF图像能见度XAML绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小问题的图像绑定到一个Radiobuttion。我只是想通过XAML绑定成为一个什么,我这样做是..我在里面createad一个StackPanel的5单选按钮。

I’ve got a little problem binding an image to a Radiobuttion. I only want to bind it via XAML an what I did is this.. I createad a Stackpanel with 5 radiobutton in it..

    <StackPanel Name="StackPanel1" Grid.Row="3" Grid.Column="1" Orientation="Horizontal" VerticalAlignment="Center">
        <RadioButton GroupName="Group1" Content="1" 
                HorizontalAlignment="Left" 
                Width="35" BorderThickness="1,0,0,1"
                IsChecked="CodeBehindBinding..." />
        <RadioButton GroupName="Group1" Content="2" 
                HorizontalAlignment="Left" VerticalAlignment="Top" 
                Width="35" BorderThickness="1,0,0,1"
                IsChecked="{CodeBehindBinding..." />
    ......

在其他地方,在XAML我tryied绑定一个标签组。总之..

Somewhere else in the XAML i tryied to bind a Label to the group. Together..

    <Image Grid.Row="3" Grid.Column="2" HorizontalAlignment="Left" Height="25" VerticalAlignment="Top" Width="25" Source="/*****;component/Resources/Checked.png" 
           Visibility="{Binding IsChecked, BindingGroupName=StackPanel1.Group1}"
           />

... Nothinig发生。 ;-)图像被永久的分享范围。

...Nothinig happens. ;-) The Image is permanent visibile.

我该如何解决?希望能帮到你..
格尔茨壹岐

How can I fix it ? Hope you can help .. Greetz Iki

推荐答案

两件事情错在这里。首先,你需要分配一个名称来要使用的绑定源和使用,对于绑定的的ElementName 属性。

Two things wrong here. First, you need to assign a Name to the RadioButton you want to use as binding source and use that for the binding's ElementName property.

<RadioButton x:Name="radioButton1" ... />

那么你的绑定也需要从布尔 A转换器能见度。你可以使用WPF的<一个href=\"http://msdn.microsoft.com/en-us/library/System.Windows.Controls.BooleanToVisibilityConverter.aspx\"相对=nofollow> BooleanToVisibilityConverter :

Then your binding also needs a converter from bool to Visibility. You could use WPF's BooleanToVisibilityConverter:

<Window.Resources>
    <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
</Window.Resources>radia

<Image Visibility="{Binding IsChecked, ElementName=radioButton1,
                    Converter={StaticResource BooleanToVisibilityConverter}}" ... />

这篇关于WPF图像能见度XAML绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆