我有一个 Flyout(下面的相关部分):
<Flyout x:Key="flyoutAverage" FlyoutPresenterStyle="{StaticResource flyoutPresenter}" Closed="Flyout_Closed">
<Grid>
<TextBox Grid.Row="1" Grid.Column="0" Text="{Binding One, Mode=TwoWay}" InputScope="Number" Margin="5,0" />
<TextBox Grid.Row="1" Grid.Column="1" Text="{Binding Two, Mode=TwoWay}" InputScope="Number" Margin="5,0" />
<TextBox Grid.Row="1" Grid.Column="2" Text="{Binding Three, Mode=TwoWay}" InputScope="Number" Margin="5,0" />
<TextBlock Grid.Row="1" Grid.Column="3" FontSize="18" VerticalAlignment="Center" Text="{Binding Average}" />
</Grid>
</Flyout>
这通过此按钮显示:
<StackPanel Orientation="Horizontal" DataContext="{Binding Neck}">
...
<Button Flyout="{StaticResource flyoutAverage}">Enter</Button>
</StackPanel>
按钮(和 Flyout)的数据上下文是该对象的一个实例:
public decimal One
{
get { return m_One; }
set { m_One = value; PropChanged("First"); PropChanged("Average"); }
}
public decimal Two
{
get { return m_Two; }
set { m_Two = value; PropChanged("Second"); PropChanged("Average"); }
}
public decimal Three
{
get { return m_Three; }
set { m_Three = value; PropChanged("Third"); PropChanged("Average"); }
}
public decimal Average
{
get
{
return (One + Two + Three) / 3;
}
}
预期的行为是,当用户单击按钮时,他们会看到以下内容:
用户在每个文本框中输入值,“平均值”文本块会自动更新为平均值。
文本框填充了正确的值,但永远不会被推回对象。当我关闭 Flyout 并重新打开它时,这些值将保留。就好像绑定模式是 OneWay,当它明确设置为 TwoWay 时。
有任何想法吗?还是我只是做错了?