为什么Slider控件的双向绑定在Windows应用商店应用中不起作用? [英] Why doesn't two-way binding of a Slider control work in a Windows Store app?
问题描述
我正在尝试在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屋!