一応こんな感じで実現はできました。
データバインディング、Prismは詳しくないので有識者にお任せします。
xaml
1<UserControl x:Class="WpfApp1.UserControlA"
2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6 xmlns:local="clr-namespace:WpfApp1"
7 mc:Ignorable="d" Height="154" Width="374">
8 <Grid>
9 <Button x:Name="Button1" Content="Button" HorizontalAlignment="Left" Margin="188,19,0,0" VerticalAlignment="Top" Height="58" Width="152"/>
10 <RadioButton x:Name="RadioButton1" Content="RadioButton" HorizontalAlignment="Left" VerticalAlignment="Top" Height="54" Width="177" Margin="0,23,0,0"/>
11 <TextBox x:Name="TextBox1" HorizontalAlignment="Left" Margin="107,108,0,0" Text="TextBox" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
12
13 </Grid>
14</UserControl>
15
16<Window x:Class="WpfApp1.MainWindow"
17 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
18 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
19 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
20 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
21 xmlns:local="clr-namespace:WpfApp1"
22 mc:Ignorable="d"
23 Title="MainWindow" Height="456" Width="574">
24 <Grid>
25 <local:UserControlA x:Name="Uc1" HorizontalAlignment="Left" Height="144" Margin="84,56,0,0" VerticalAlignment="Top" Width="400"/>
26 <local:UserControlA x:Name="Uc2" HorizontalAlignment="Left" Height="144" Margin="84,248,0,0" VerticalAlignment="Top" Width="400"/>
27
28 </Grid>
29</Window>
30
[MainWindow.xaml.cs]
C#
1using System.Windows;
2using System.Windows.Controls;
3
4namespace WpfApp1
5{
6 /// <summary>
7 /// Interaction logic for MainWindow.xaml
8 /// </summary>
9 public partial class MainWindow : Window
10 {
11 public MainWindow()
12 {
13 InitializeComponent();
14
15 Uc1.Button1.Click += OnButtonClick;
16 Uc2.Button1.Click += OnButtonClick;
17 }
18
19 private void OnButtonClick(object sender, RoutedEventArgs e)
20 {
21 FrameworkElement host = null;
22 for (host = (FrameworkElement)((Button)sender).Parent; !(host is UserControlA); host = (FrameworkElement)host.Parent);
23
24 UserControlA uc = (UserControlA)host;
25 uc.TextBox1.Text = "Hello World!";
26 }
27 }
28}
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/05/02 07:31
2020/05/02 07:51