我有三个用户控件。
用户控制 1
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Gramercy"
mc:Ignorable="d"
x:Class="wpfapplication.UCManageQALibrary"
x:Name="UserControl"
d:DesignWidth="774" d:DesignHeight="529.723">
<Grid x:Name="LayoutRoot">
<Grid>
<Button Content="List QA" x:Name="btnSearchQAStructure" Click="Button_Click_1" />
<Button Content="Add New QA" x:Name="btnAddNewQAStructure" Click="Button_Click" />
<local:UCSearchQALibrary x:Name="searchQALibrary" Visibility="Visible"/>
<local:AddNewQA x:Name="addQALibrary" Visibility="Hidden"/>
</Grid>
</Grid>
</UserControl>
用户控制 2
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006
mc:Ignorable="d"
x:Class="wpfapplication.AddNewQA"
x:Name="UserControl"
d:DesignWidth="1280" d:DesignHeight="1024">
<Grid x:Name="LayoutRoot">
<Grid>
<Label x:name="Label1" Content="" />
</Grid>
</Grid>
</UserControl>
和用户控制 3
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="wpfapplication.UCSearchQALibrary"
x:Name="UserControl"
d:DesignWidth="758" d:DesignHeight="486.905">
<Grid x:Name="LayoutRoot" >
<GroupBox Header="Question and Answer Master Library" >
<Grid Margin="8">
<WrapPanel Margin="4,0,0,0" VerticalAlignment="Stretch">
<ListView Margin="4,10,0,10" x:Name="lvQA" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Auto" AlternationCount="2" VerticalAlignment="Stretch" Height="420">
<ListView.View>
<GridView>
<GridViewColumn >
<GridViewColumn.HeaderTemplate>
<DataTemplate>
<Label Content="Q & A Search Result : " FontSize="12" FontWeight="Bold" Margin="0,4,0,4"/>
</DataTemplate>
</GridViewColumn.HeaderTemplate>
<GridViewColumn.CellTemplate>
<DataTemplate>
<StackPanel>
<Button Content="{Binding Path=QuestionText}" Margin="4,10,8,4" Style="{StaticResource HyperlinkLikeButton}" VerticalAlignment="Top" Click="Button_Click" CommandParameter="{Binding Path=QuestionID}" />
<TextBlock TextWrapping="Wrap" Margin="4,0,4,4" HorizontalAlignment="Stretch"><Run Text="{Binding Path=AnswerText}"/></TextBlock>
</StackPanel>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
</WrapPanel>
</Grid>
</GroupBox>
</Grid>
</UserControl>
用户控件 2 用于添加新的问题答案,用户控件 3 用于提供已创建问题答案的列表。用户控件 1 具有用户控件 2 和 3。一次用户控件 2 或 3 是可见的。在用户控件 1 中,单击列表 QA 按钮时,用户控件 3 可见,而用户控件 2 不可见。单击添加新 QA 按钮时,用户控件 2 可见,用户控件 3 不可见。
现在,在用户控件 3 中,我有一个与列表视图的每一行关联的按钮。在点击/单击该按钮时,我需要一个功能来使用户控件 2 可见并将用户控件 2 内的标签与特定内容绑定。
我曾尝试过路由事件。
在用户控件 3 中,我添加了...
public static readonly RoutedEvent AddClickEvent = EventManager.RegisterRoutedEvent("AddClick", RoutingStrategy.Direct, typeof(RoutedEventHandler), typeof(Button));
public event RoutedEventHandler AddClick
{
add { AddHandler(AddClickEvent, value); }
remove { RemoveHandler(AddClickEvent, value); }
}
void RaiseAddClickEvent()
{
RoutedEventArgs newEventArgs = new RoutedEventArgs(UCSearchQALibrary.AddClickEvent);
}
private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
{
// TODO: Add event handler implementation here.
//Thread newWindowThread = new Thread(new ThreadStart(ThreadStartingPoint));
//newWindowThread.SetApartmentState(ApartmentState.STA);
//newWindowThread.IsBackground = true;
//newWindowThread.Start();
RaiseEvent(new RoutedEventArgs(AddClickEvent));
}
在用户控件 1 中,我添加了...
local:UCSearchQALibrary.AddClick="dCB_Props_AddClick"
private void dCB_Props_AddClick(object sender, System.Windows.RoutedEventArgs e)
{
MessageBox.Show("This Works");
}
任何帮助将不胜感激。
谢谢。