Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用从WinRt Xaml Toolkit中选择的ListBoxItemExtensions.iss不会';不能双向装订_C#_Xaml_Windows Runtime_Winrt Xaml_Winrt Xaml Toolkit - Fatal编程技术网

C# 使用从WinRt Xaml Toolkit中选择的ListBoxItemExtensions.iss不会';不能双向装订

C# 使用从WinRt Xaml Toolkit中选择的ListBoxItemExtensions.iss不会';不能双向装订,c#,xaml,windows-runtime,winrt-xaml,winrt-xaml-toolkit,C#,Xaml,Windows Runtime,Winrt Xaml,Winrt Xaml Toolkit,在Windows RT应用程序(c#)中,我使用以下命令: <ListBox ItemsSource="{Binding Path=FilterBaseFields}" SelectionMode="Multiple"> <ListBox.ItemTemplate > <DataTemplate > <TextBox Text="{Binding Path=

在Windows RT应用程序(c#)中,我使用以下命令:

<ListBox ItemsSource="{Binding Path=FilterBaseFields}" SelectionMode="Multiple">
            <ListBox.ItemTemplate >
                <DataTemplate  >
                    <TextBox Text="{Binding Path=Key, Mode=TwoWay}" 
                  extensions:ListBoxItemExtensions.IsSelected="{Binding Path=IsSelected, Mode=TwoWay}"/>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

对于文本,双向绑定非常有效,但对于扩展:ListBoxItemExtensions.IsSelected-不起作用(仅从源代码到视图起作用)。
你知道吗

我问它已经打开了,然后回答:

对。这似乎是该属性的一个限制。我们需要创建一个不同的绑定来支持双向绑定。类似于“IsSelectedBinding”属性的东西,使用我在这里描述的模式: 也许当我有机会的时候,我会把它添加到工具箱中

我用电脑解决了我的问题

它看起来像:

public class MyListBox : ListBox
{
    protected override void PrepareContainerForItemOverride(
        DependencyObject element, object item)
    {
        base.PrepareContainerForItemOverride(element, item);

        if (item is Item)
        {
            var binding = new Binding
            {
                Source = item,
                Path = new PropertyPath("IsSelected"),
                Mode = BindingMode.TwoWay
            };

            ((ListBoxItem)element).SetBinding(ListBoxItem.IsSelectedProperty, binding);
        }
    }
}
我问它已经打开了,回答说:

对。这似乎是该属性的一个限制。我们需要创建一个不同的绑定来支持双向绑定。类似于“IsSelectedBinding”属性的东西,使用我在这里描述的模式: 也许当我有机会的时候,我会把它添加到工具箱中

我用电脑解决了我的问题

它看起来像:

public class MyListBox : ListBox
{
    protected override void PrepareContainerForItemOverride(
        DependencyObject element, object item)
    {
        base.PrepareContainerForItemOverride(element, item);

        if (item is Item)
        {
            var binding = new Binding
            {
                Source = item,
                Path = new PropertyPath("IsSelected"),
                Mode = BindingMode.TwoWay
            };

            ((ListBoxItem)element).SetBinding(ListBoxItem.IsSelectedProperty, binding);
        }
    }
}