为什么Slider控件的双向绑定在Windows应用商店应用中不起作用? [英] Why doesn't two-way binding of a Slider control work in a Windows Store app?

查看:78
本文介绍了为什么Slider控件的双向绑定在Windows应用商店应用中不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Windows应用商店应用中执行一些简单的绑定。一些控件例如 ToggleButton 绑定正常,但是当绑定 Slider 时,UI中的更改不会反映在绑定对象中。



数据源是 ObservableCollection< Film> 电影有一些属性包括:

I am trying to perform some simple binding in a Windows Store app. Some controls e.g. ToggleButton bind fine, but when a Slider is bound, changes in the UI are not reflected in the bound object.

The data source is an ObservableCollection<Film>. Film has some properties including:

public bool Seen { get; set; } // Actually INotifyPropertyChanged is implemented
public int Rating { get; set; } // on both.



XAML就像(为简洁起见而简化):


The XAML is like (simplified for clarity):

<Page DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}">
    <FlipView DataContext="{Binding Group}" ItemsSource="{Binding Source={StaticResource itemsViewSource}}">
        <FlipView.ItemTemplate>
            <DataTemplate>
                <StackPanel>
                    <ToggleButton Content="Seen It" IsChecked="{Binding Seen, Mode=TwoWay}"> 
                    <Slider Value="{Binding Rating, Mode=TwoWay}" IsEnabled="{Binding Seen}" Etc="the usual properties set here.">
                </StackPanel>
            </DataTemplate>
        </FlipView.ItemTemplate>
    </FlipView>
</Page>



当用户互动时使用 ToggleButton 电影的Seen属性已更新。 评级属性永远不会更改。我必须在后面的代码中手动更新业务对象。



我一直在谷歌上搜索。我找不到绑定 Slider.Value 的其他示例。每个人都有兴趣将它绑定到 TextBox 的值。


When the user interacts with the ToggleButton, the Film's Seen property is updated. The Rating property never changes. I have to manually updated the business object in code behind.

I have been googling all day. I couldn't find other examples of binding Slider.Value. Everyone is interested in binding it to the value of a TextBox.

推荐答案

这篇关于为什么Slider控件的双向绑定在Windows应用商店应用中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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