English 中文(简体)
WPF 数据输入
原标题:WPF Databound RadioButton ListBox

我在WPF中看到一个有数据限制的无线电台清单箱,以应对用户的投入,并反映它所约束的数据的变化(即改变代码)。 用户投入方进行罚款(即,我可以选择一个无线电布局,名单按预期操作)。 但是,改变法典选择的每一尝试都失败了。 沉默(即无例外)。

兹将XAML的有关部分(我想):

<Setter Property="ItemContainerStyle">
<Setter.Value>
    <Style TargetType="{x:Type ListBoxItem}" >
        <Setter Property="Margin" Value="2" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ListBoxItem}">
                    <Border Name="theBorder" Background="Transparent">
                    <RadioButton Focusable="False" IsHitTestVisible="False" 
                        IsChecked="{Binding Path=IsSelected, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}" >
                        <ContentPresenter />
                    </RadioButton>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</Setter.Value>

我将清单箱装到学校目标清单中。 “学校财产”包括一个称为IsS当选的财产:

    public bool IsSelected
    {
        get { return isSelected; }

        set
        {
            if( value != isSelected )
            {
                isSelected = value;
                this.OnPropertyChanged("IsSelected");
            }
        }
    }

在我试验期间,“OnpertyChanged()”是我所言。 它没有解决问题。

诸如下列情况:

((SchoolInfo) lbxSchool.Items[1]).IsSelected = true;
lbxSchool.SelectedIndex = 1;

他们无声无声地 fail击——没有例外,但德国马克没有显示正在选择的项目。

问题回答

博特顿电台对名单BoxItem IsS选择的财产具有约束力,而不是对你学校Info IsS选择的财产具有约束力。

(令人困惑的是,名单BoxItem有“我选择的”财产,而且你的学校Info也这样做,这就是为什么没有具有约束力的错误。)

为了确定,清单BoxItem。 伊斯梅尔当选后,必须服从于埃内福·伊斯梅尔当选后的财产。

i.e. 你们需要一个额外单元,以便把清单BoxItem与学校信息联系起来。 IsS当选,然后名单箱子项目将按原样运作,而Button电台也可正确约束名单BoxItem。 伊斯梅尔当选。

<Style TargetType="{x:Type ListBoxItem}" >
    <Setter Property="IsSelected" Value="{Binding Path=IsSelected}" />

我将允许在你的Button广播电台发布最新消息。 尽管你允许双向具有约束力的通知(即违约),但除非你明确倾听通知,否则从表面上的变化中收回通知。

<RadioButton Focusable="False" IsHitTestVisible="False" 
                    IsChecked="{Binding Path=IsSelected, RelativeSource={RelativeSource TemplatedParent}, NotifyOnSourceUpdated=True}" >




相关问题
WPF convert 2d mouse click into 3d space

I have several geometry meshes in my Viewport3D, these have bounds of (w:1800, h:500, d:25). When a user clicks in the middle of the mesh, I want the Point3D of (900, 500, 25)... How can I achieve ...

Editing a xaml icons or images

Is it possible to edit a xaml icons or images in the expression design or using other tools? Is it possible to import a xaml images (that e.g you have exported) in the expression designer for editing?...

WPF: writing smoke tests using ViewModels

I am considering to write smoke tests for our WPF application. The question that I am faced is: should we use UI automation( or some other technology that creates a UI script), or is it good enough to ...

WPF - MVVM - NHibernate Validation

Im facing a bit of an issue when trying to validate a decimal property on domain object which is bound to a textbox on the view through the viewmodel. I am using NHibernate to decorate my property on ...

How do WPF Markup Extensions raise compile errors?

Certain markup extensions raise compile errors. For example StaticExtension (x:Static) raises a compile error if the referenced class cannot be found. Anyone know the mechanism for this? Is it baked ...

WPF design-time context menu

I am trying to create a custom wpf control, I m wondering how I can add some design-time features. I ve googled and can t seem to get to my goal. So here s my simple question, how can I add an entry ...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签