【发布时间】:2019-06-29 13:30:11
【问题描述】:
拥有一个 WPF 用户控件和一个包含 DevExpress GridControl 的 DockPanel,以及在 GridControl 之后和之外的一个 TextBox:
<UserControl x:Class="HellerOven.Setup.SetupGUI.WatlowView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:resx="clr-namespace:HellerOven.Languages"
xmlns:local="clr-namespace:HellerOven.Setup.SetupGUI"
xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<DockPanel>
<dxg:GridControl x:Name="WatlowSensorsGrid" EnableSmartColumnsGeneration="True" DockPanel.Dock="Top" ItemsSource="{Binding}" FontSize="14" FontWeight="Medium" Height="600" Margin="0,20,0,0">
...
</dxg:GridControl>
<TextBox Text="Alarm activation delay [seconds]" IsReadOnly="True" FontSize="14" Foreground="RoyalBlue" FontWeight="Medium" BorderThickness="0" Height="30"/>
<TextBox Text="30" Name="alarmActivationDelay" FontSize="14" Foreground="RoyalBlue" FontWeight="Medium" BorderThickness="1" Width="100" Height="30"/>
<Button Height="35" Width="200" Click="Add_Button_Click" HorizontalAlignment="Center" DockPanel.Dock="Bottom" Margin="0,50,0,0">
<StackPanel Orientation="Horizontal">
<Image Source="{dx:DXImage Image=Add_32x32.png}" Stretch="Uniform"/>
<TextBlock Text="Add Watlow Sensor" VerticalAlignment="Center" Margin="5 0 0 0" FontSize="14"/>
</StackPanel>
</Button>
</DockPanel>
在 UserControl 的 C# 构造函数中,我为 GridControl 和 TextBox 指定了单独的 DataContext:
public WatlowView()
{
InitializeComponent();
WatlowSensorsGrid.DataContext = OvenCollections.Instance.SetupWizard.WatlowSensors;
alarmActivationDelay.DataContext = OvenCollections.Instance.SetupWizard.alarmActivationDelay;
}
在程序执行期间,GridControl 及其成员在其分配的 DataContext 中更新,但简单整数“alarmActivationDelay”未在其分配的 DataContext 中更新。我对 DataContext 有什么误解?谢谢。
【问题讨论】:
标签: wpf data-binding