セカンダリウィンドウにあるテキストボックスのテキストプロパティを、そのセカンダリウィンドウの対応するビューモデルで定義されているプロパティにバインドする必要があります
XAMLコード:
<Window x:Class="RG.IOManager.Views.PreferencesDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:genericClasses="clr-namespace:RG.IOManager.GenericClasses"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
Title="Setup" Height="131" Width="332"
WindowStartupLocation="CenterOwner"
ShowInTaskbar="False"
WindowStyle="ToolWindow"
>
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="../ResourceDictionary.xaml" />
<ResourceDictionary Source="../ScrollBarTemplate.xaml" />
<ResourceDictionary Source="../Styles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="10*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Label Content="Cycle Time" Grid.Row="0" Grid.Column="0" Height="28" HorizontalAlignment="Left" Margin="10,10,0,20" Name="label1" VerticalAlignment="Top" />
<StackPanel Grid.Row="0" Grid.Column="1" Width="190" Orientation="Horizontal">
<!--
<xctk:IntegerUpDown Name="TbMainCycleTime" Margin="10,10,0,20" Width="50" Height="25" HorizontalContentAlignment="Right"
Increment="1" Maximum="5000" Minimum="0" ShowButtonSpinner="False"/>
-->
<TextBox Name="TbMainCycleTime" Margin="10,10,0,20" Width="50" Height="25" HorizontalContentAlignment="Right" Validation.ErrorTemplate="{StaticResource ErrorTemplate}" Style="{StaticResource textBoxErrorTooltip}" >
<TextBox.Text>
<Binding Source="PreferencesDialog" Path="CycleTime" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged" >
<Binding.ValidationRules>
<genericClasses:IntegersValidation Min="0" Max="1000" />
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
</TextBox>
<!--<TextBox Name="TbMainCycleTime" Margin="10,10,0,20" Width="50" Height="25" HorizontalContentAlignment="Right" />-->
<Label Content="ms" Margin="1,10,10,20"/>
</StackPanel>
<StackPanel Grid.Row="1" Grid.Column="1" Width="190" Orientation="Horizontal">
<Button Content="Update" Height="23" HorizontalAlignment="Left" Margin="5,0,10,0" Name="btUpdate" VerticalAlignment="Top" Width="75" Click="btUpdate_Click" />
<Button Content="Cancel" Height="23" HorizontalAlignment="Left" Margin="5,0,10,0" Name="btCancel" VerticalAlignment="Top" Width="75" Click="btCancel_Click" />
</StackPanel>
</Grid>
CSコード:
/// <summary>
/// Interaction logic for PreferencesDialogue.xaml
/// </summary>
public partial class PreferencesDialog : Window, INotifyPropertyChanged
{
#region Binding Properties
public event PropertyChangedEventHandler PropertyChanged;
/// <summary>
/// Main cycle time
/// </summary>
public int CycleTime
{
get { return _CycleTime; }
set
{
_CycleTime = value;
var handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs("CycleTime"));
}
}
}
private int _CycleTime;
#endregion
private IOManager _receiver;
public PreferencesDialog(IOManager receiver)
{
this._receiver = receiver;
InitializeComponent();
//this.TbMainCycleTime.Text = _receiver.globalBindingProperties.MainCycleTime.ToString();
this.CycleTime = _receiver.globalBindingProperties.MainCycleTime;
}
private void btUpdate_Click(object sender, RoutedEventArgs e)
{
_receiver.globalBindingProperties.MainCycleTime = Convert.ToInt32(this.TbMainCycleTime.Text);
this.Close();
}
private void btCancel_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
}
誰かが私が間違ったことを見つけるのを手伝ってくれますか?前もって感謝します