我有一个 gridView,并为我的中心页面绑定了我的 ObservableCollection 不同的类项。将不同的类项绑定到gridView,并显示不同的项数据模板、表头模板。
我在gridview的标题模板中使用用户控件。我的标题模板,包括用户控件和用户控件,包括一些组合框。我想通过pageRoot对象上的参数将pageRoot datacontext集合绑定到headertemplate组合框中。
我正在创建一个用户控件并创建一些 DependencyProperty、组合框事件处理程序。但无法将 pageRoot DataContext 集合绑定到用户控件组合框中:(
我的英语很差,对这种情况感到抱歉;)感谢您的回答..
我的标题数据模板:
<DataTemplate x:Key="OrganizationFixtureHeaderTemplate">
<Grid Margin="6">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0">
<TextBlock Text="{Binding Title}" Style="{StaticResource TitleTextStyle}"/>
</StackPanel>
<UserControls:UcCbOrganizationFixtureSelections
Grid.Column="1"
RootElement="pageRoot"
PageOrganizationSource="{Binding PageOrganization, ElementName=pageRoot}"
/>
</Grid>
</DataTemplate>
我的用户控制代码:
<UserControl
x:Class="Modern_UI.Common.UserControls.UcCbOrganizationFixtureSelections"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Modern_UI.Common.UserControls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<StackPanel Orientation="Horizontal">
<ComboBox x:Name="cbOrgFixtureSeasons"
ItemsSource="{Binding Path=DataContext.Seasons, ElementName=RootElement}"
SelectedValuePath="Id"
DisplayMemberPath="Name"
SelectionChanged="CbOrgFixtureSeasons_OnSelectionChanged"
Width="Auto"
Height="Auto"
/>
<ComboBox x:Name="cbOrgFixtureStages"
ItemsSource="{Binding Path=DataContext.FixtureStages, ElementName=RootElement}"
SelectedValuePath="Id"
DisplayMemberPath="Name"
SelectionChanged="CbOrgFixtureStages_OnSelectionChanged"
Width="Auto"
Height="Auto"
/>
<ComboBox x:Name="cbOrgFixtureRounds"
ItemsSource="{Binding Path=DataContext.FixtureRounds, ElementName=RootElement}"
SelectedValuePath="Id"
DisplayMemberPath="Name"
SelectionChanged="CbOrgFixtureRounds_OnSelectionChanged"
Width="Auto"
Height="Auto"
/>
</StackPanel>
</UserControl>
后面的用户控制代码:
namespace Modern_UI.Common.UserControls
{
public sealed partial class UcCbOrganizationFixtureSelections : UserControl
{
public DependencyProperty RootElementProperty = DependencyProperty.Register("RootElement",
typeof(string),
typeof(
UcCbOrganizationFixtureSelections
),
null);
public DependencyProperty PageOrganizationSourceProperty = DependencyProperty.Register("PageOrganizationSource",
typeof(Organization),
typeof(
UcCbOrganizationFixtureSelections
),
null);
public string RootElement
{
get { return this.GetValue(RootElementProperty) as string; }
set { this.SetValue(RootElementProperty, value); }
}
public Organization PageOrganizationSource
{
get { return this.GetValue(PageOrganizationSourceProperty) as Organization; }
set { this.SetValue(PageOrganizationSourceProperty, value); }
}
public UcCbOrganizationFixtureSelections()
{
this.InitializeComponent();
}
async private void CbOrgFixtureSeasons_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
//loading root page parameter via "PageOrganizationSource" named DependencyProperty.
}
}