视窗10×:绑定到的SelectedItem [英] Windows 10 x:Bind to SelectedItem

查看:129
本文介绍了视窗10×:绑定到的SelectedItem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图端口/采纳我的Windows RT应用WIndows10,我尝试了新的绑定X:。绑定

I'm trying to port/adopt my Windows RT app to WIndows10 and I'm trying out the new bindings x:Bind.

到目前为止,我能够绑定到我的ViewModel属性和其他Viewelements。但现在我想一个文本框的文本绑定到一个GridView的的SelectedItem。

So far I'm able to bind to my ViewModel properties and other Viewelements. But now I'm trying to bind the text of a TextBox to a SelectedItem of a GridView.

在经典结合我做的这样。

In classic binding I'm doing it like that.

<TextBox x:Name="tb_textgroup"
                             Grid.Row="1"
                             PlaceholderText="Change Groupname"
                             Text="{Binding UpdateSourceTrigger=PropertyChanged,
                                    ElementName=gv_textgroup,
                                    Mode=TwoWay,Path=SelectedItem.bezeich}"
                             IsEnabled="{Binding UpdateSourceTrigger=PropertyChanged,
                                       ElementName=gv_textgroup,
                                       Mode=TwoWay,Path=SelectedItem.edit_activated}"
                             Margin="20,10,20,0"
                             />

我和尝试它


  • 文本={X:绑定gv_textgroup.SelectedItem.bezeich,模式=双向}

  • 文本={X:绑定textgroup [gv_textgroup.SelectedIndex] .bezeich,模式=双向}

    • 其中textgroup是我viewmodelclass所有元素

    但它没有工作...任何想法?

    But None of it worked... any ideas?

    和有人可以解释我做什么用的DependencyProperty。我看了VIEDO从建设2015,并有样品codeS。但它说什么,我...我很是新手...

    And can someone explain me what to do with "DependencyProperty". I watched the viedo from "build 2015" and have the sample codes. But it's saying nothing to me... I'm quite a newbie...

    非常感谢您的帮助。

    推荐答案

    我不知道为什么这个工作,但是如果你创建一个对象到对象的转换器, X:绑定适用于任何双向转换的SelectedItem

    I'm not sure why this works, but if you create an object-to-object converter, x:Bind works for two-way conversion on any SelectedItem.

    public class NoopConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            return value;
        }
    
        public object ConvertBack(object value, Type targetType, object parameter, string language)
        {
            return value;
        }
    }
    

    和您可以使用它是这样的:

    And you can use it like this:

    <ListView ItemsSource="{x:Bind ViewModel.Items}"
             SelectedItem="{x:Bind ViewModel.SelectedItem, Mode=TwoWay, Converter={StaticResource NoopConverter}}"
             ...
    

    特别感谢 runceel 他的公众样本。

    Special thanks to runceel for his public samples.

    他解释说在这里 日语。

    He explains it here in Japanese.

    这篇关于视窗10×:绑定到的SelectedItem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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