我目前正在使用click事件在UserControl中保存文件数据(通过后台工作程序),在每个步骤中更新主窗口中的控件,该控件运行良好并从UserControl获取更新。代码如下。
更新:我应该声明我使用的是FirstFloor MUI框架和主窗口中的mui:ModernTab。
MainWindow.xaml控件(控件在更新发生前隐藏)(使用x:FieldModifier =" public")
<StatusBar x:Name="mainStatus" Height="24" VerticalAlignment="Bottom" Panel.ZIndex="999999" BorderThickness="0,1,0,0" BorderBrush="#FFBDBDBD" Background="Transparent" Margin="0,0,0,-15">
<StackPanel x:Name="global_message" Height="28" Width="718" x:FieldModifier="public" Margin="0,4,0,0" Visibility="Hidden">
<fa:ImageAwesome x:Name="global_message_block_icon" x:FieldModifier="public" Height="12" Width="15" HorizontalAlignment="Left" Visibility="Hidden" >
<fa:ImageAwesome.Foreground>
<SolidColorBrush Color="{DynamicResource AccentColor}"/>
</fa:ImageAwesome.Foreground>
</fa:ImageAwesome>
<TextBlock x:Name="global_message_block" x:FieldModifier="public" Margin="19,-13,0,0" HorizontalAlignment="Left" Height="15" Width="850" FontSize="12" FontWeight="Bold" Visibility="Hidden" >
<TextBlock.Foreground>
<SolidColorBrush Color="{DynamicResource AccentColor}"/>
</TextBlock.Foreground>
</TextBlock>
</StackPanel>
</StatusBar>
用于更新MainWindow +中所选控件的UserControl(MyControlA.xaml.cs)代码可能更新另一个UserControl中的另一个控件(ProcessTools / PODDuplicate.xaml)
//Works well
foreach (System.Windows.Window window in System.Windows.Application.Current.Windows)
{
if (window.GetType() == typeof(MainWindow))
{
(window as MainWindow).global_message.Visibility = Visibility.Hidden;
(window as MainWindow).global_message_block.Text = "";
(window as MainWindow).global_message_block.ToolTip = "";
}
}
//Code to access ProcessTools.PODDuplicate(ProcessTools/PODDuplicate.xaml) which has the control I wish to change/update
foreach (UserControl usercontrol in System.Windows.Application.Current.Windows)
{
if (usercontrol.GetType() == typeof(UserControl))
{
(usercontrol as ProcessTools.PODDuplicate).form_process_pod.Visibility = Visibility.Hidden;
}
}
问题在于;
foreach (UserControl usercontrol in System.Windows.Application.Current.Windows)
永远不会起作用,因为需要更新的对象是控件而不是窗口类型。
是否可以访问&#34;其他UserControl&#34;并更新控件设置?