如何从其他项目更改wpf用户内容。例如,我有两个用户控制项目。当第二个wpf用户项目中的时钟打勾时,我想在第一个用户控制项目中更改文本框。可能吗 ?如何从其他项目更改wpf用户内容
第一个项目
<UserControl x:Class="StatusBar.StatusBarWindow"
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"
mc:Ignorable="d"
d:DesignHeight="30" d:DesignWidth="800">
<Grid>
<StatusBar VerticalAlignment="Bottom" Grid.Column="0" Background="{x:Null}">
<StatusBarItem HorizontalAlignment="Right">
<TextBox x:Name="TxtClock" IsReadOnly="True" Background="{x:Null}" BorderThickness="0" Foreground="Black" x:FieldModifier="public" Text="i want change" />
</StatusBarItem>
</StatusBar>
</Grid>
第二个项目
DispatcherTimer clock = new DispatcherTimer();
TxtSaat.Text = string.Format("{0:HH:mm:ss}", DateTime.Now);
clock.Tick += new EventHandler(Clock_Tick);
clock.Interval = new TimeSpan(0, 0, 1);
clock.Start();
private void Clock_Tick(object sender, EventArgs e)
{
TxtClock.Text = string.Format("{0:HH:mm:ss}", DateTime.Now);
}
我做到了。但用户控制不更新。 –
让我猜。你在窗口中有一个用户控件,并且你使用'... = new MyUserControl();'创建了一个实例,你运行更新并且现在显示没有更新? –
是的。你是对的。 –