我在現場尋找答案,但沒有找到。我有一個 Windows 模板,在模板中,我有一個文本框。
<TextBox x:Name="WindowTextbox" Text="Type..." TextChanged="WindowTextbox_TextChanged"
FontSize="15" Foreground="White" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto"
AcceptsReturn="True" Background="#404040" BorderThickness="0" Grid.Row="0" Grid.Column="0"
Grid.ColumnSpan="3" Grid.RowSpan="3" Margin="0 0 0 23">
</TextBox>
另外,當我按下動態創建的文本框的按鈕時,我創建了另一個文本框。
void Button_Click_1(object sender, RoutedEventArgs e)
{
var window = new Window();
window.Show();
window.Width = 250;
window.Height = 250;
window.Template = FindResource("WindowControlTemplate1") as ControlTemplate;
TextBox dynamicTextBox = new TextBox();
Grid.SetRow(dynamicTextBox, 1);
Grid.SetColumn(dynamicTextBox, 0);
this.TextPanel.Children.Add(dynamicTextBox);
}
所以我想做的是,當我在模板內的文本框中同時寫一些東西時,這個文本應該出現在動態創建的文本框中
uj5u.com熱心網友回復:
如果我理解正確的話。
而不是這個
TextBox dynamicTextBox = new TextBox();
制作私人領域
private TextBox _dynamicTextBox;
void Button_Click_1(object sender, RoutedEventArgs e)
{
...
...
_dynamicTextBox = new TextBox();
Grid.SetRow(dynamicTextBox, 1);
Grid.SetColumn(dynamicTextBox, 0);
this.TextPanel.Children.Add(_dynamicTextBox);
}
TextChanged如果您WindowTextbox將文本設定為您的_dynamicTextBox.
private void WindowTextbox_TextChanged(object sender, TextChangedEventArgs e)
{
if(sender is TextBox txt)
{
_dynamicTextBox.Text = txt.Text;
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/431361.html
上一篇:不變違規:模塊“AppRegistry”不是注冊的可呼叫模塊(呼叫“runApplication”)。等等
下一篇:在WPF中變形形狀
