I found an answer there is needed implementation of INotifyPropertyChanged for tempaltes properties.
ContentControl doesnt show data
BitSmithy
2,206
Reputation points
Hello
I defined UserControl in UWP XAML, but It doesnt show any data:
<UserControl
x:Class="Financial_Planner.BSListView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Financial_Planner"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400">
<UserControl.Resources>
<DataTemplate x:Key="AAA">
<TextBox Text="AAAAAAAAAAAAAAAAAAAAAAa"></TextBox>
</DataTemplate>
</UserControl.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition x:Name="HeaderArea" Height="Auto"></RowDefinition>
<RowDefinition x:Name="UpperSummariesArea" Height="Auto"></RowDefinition>
<RowDefinition x:Name="ListViewArea" Height="*"></RowDefinition>
<RowDefinition x:Name="DownSummariesArea" Height="Auto"></RowDefinition>
<RowDefinition x:Name="TestRow" Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<ContentControl MinHeight="300" MinWidth="300"
x:Name="ccHeaderArea" Grid.Row="0"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch"
Content="{x:Bind HeaderDataSource, Mode=OneWay}"
ContentTemplate="{x:Bind HeadersTemplate, Mode=OneWay}"
>
</ContentControl>
</Grid>
code behind
public sealed partial class BSListView : UserControl
{
public DataTemplate HeadersTemplate { get; set; }
public DataTemplate UpperSummariesTemplate { get; set; }
public DataTemplate ItemsTemplate { get; set; }
public DataTemplate DownSummariesTemplate { get; set; }
public object HeaderDataSource { get; set; }
public object UpperSummariesDataSource { get; set; }
public IEnumerable ListViewItemsSource { get; set; }
public object DownSummariesDataSource { get; set; }
public BSListView()
{
this.InitializeComponent();
lv.ItemsSource = this.ListViewItemsSource;
}
public void Init<T>(ObservableCollection<T> source)
{
this.HeadersTemplate = this.Resources["AAA"] as DataTemplate;
}
}
}
Next I declare my user control in my app xaml and code behind i use command myDeclaredUserControl.Init(). There should be showed HeadersTemplate with AAAAAAA text, but is not, why? The same problem is If I want to pass HeadersTemplate from my app to UserControll. How to fix my problem.