In my case, i have a control named MultiSelectListView.xaml which holds the dataTemplate
<DataTemplate x:Key="ListTemplate" x:DataType="model:BaseMultiSelectModel">
<Grid Margin="32,0,20,0" BorderThickness="0,0,0,1" BorderBrush="{ThemeResource SystemControlBackgroundChromeMediumBrush}" Background="Transparent">
<Grid Margin="0,12,0,12">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<CheckBox IsChecked="{x:Bind IsChecked, Mode=TwoWay}" MinWidth="0"/>
<ContentControl Grid.Column="1" HorizontalAlignment="Stretch" Content="{Binding}" ContentTemplate="{Binding ListTemplate, ElementName=MultiSelectList, Mode=OneWay}"/>
</Grid>
</Grid>
</DataTemplate>
I have a Dependency Property in MultiSelectListView.xaml.cs named ListTemplate which holds the rest of the DataTemplate which i displayed through ContentControl inside DataTemplate.
In my UserView.xaml
<controls:MultiSelectListView IsLoading="{x:Bind ProjectUserModel.IsLoading, Mode=OneWay}"
IsSelectallChecked="{x:Bind ProjectUserModel.IsSelectallChecked, Mode=TwoWay}"
ItemsSource="{x:Bind ProjectUserModel.ItemsList, Mode=OneWay}">
<controls:MultiSelectListView.ListTemplate>
<DataTemplate x:DataType="model:UserModel">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="300"/>
<ColumnDefinition Width="{Binding IsColumn2Visible, ElementName=UserView, Mode=OneWay}"/>
<ColumnDefinition Width="{Binding IsColumn3Visible, ElementName=UserView, Mode=OneWay}"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" Margin="10,0,0,0">
<TextBlock Text="{x:Bind name, Mode=OneWay}" Style="{StaticResource TextBlockStyle}"/>
<TextBlock Foreground="{StaticResource SystemControlForegroundBaseMediumBrush}" Margin="0,5,0,0" Text="{x:Bind email, Mode=OneWay}" Style="{StaticResource TextBlockStyle}"/>
</StackPanel>
<TextBox Grid.Column="1" VerticalAlignment="Center" Margin="5,0,25,0" Text="{x:Bind value2, Mode=TwoWay}" BorderThickness="1"/>
<TextBox Grid.Column="2" VerticalAlignment="Center" Margin="5,0,25,0" Text="{x:Bind value3, Mode=TwoWay}" BorderThickness="1"/>
</Grid>
</DataTemplate>
</controls:MultiSelectListView.ListTemplate>
</controls:MultiSelectListView>
In UserView.xaml, x:Bind is working fine. but for binding the column visibility the value will not be available in UserModel. Hence used Binding to fetch from the UserView.xaml.cs. As i used DataTemplate, The Template directly applies to the MultiSelectListView's ContentControl and trying to obtain the IsColumn2Visible, IsColumn3Visible which will not be available there.
My Question is how do i bind the Column visiblity with IsColumn2Visible, ISColumn3Visible ? Please don't prefer individual DependencyProperty on MultiSelectListView.xaml for all Visiblity property, hence the binding ListTemplate is dynamic.