I found many threads about this topic but couldn't make my app working, so I ask a new question here.
I want to make a UserControl-element that has a Grid that can be filled from outside. this is the UserControl-Xaml-Part:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="70"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="70"/>
</Grid.ColumnDefinitions>
<Grid Grid.Column="2" x:Name="ButtonGrid"/>
</Grid>
Outside in my MainPage.xaml I want to use it like this:
<UserControls:MyControl>
<UserControls:MyControl.ButtonGrid>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="130"/>
<ColumnDefinition Width="130"/>
<ColumnDefinition Width="130"/>
<ColumnDefinition Width="130"/>
</Grid.ColumnDefinitions>
// Add elements and stuff
</Grid>
</UserControls:MyControl.ButtonGrid>
</UserControls:AppBar>
But I don't get this far. It says that "ButtonGrid" was not recognized or couldn't access Member (my translation from german error-message). But when I type UserControls:MyControl.
it suggests ButtonGrid
.
The MyControl.xaml.cs looks like this:
namespace myApp
{
public partial class MyControl: UserControl
{
public Grid ButtonGrid { get; set; }
// or
public Grid ButtonGrid
{
get { return (Grid)GetValue(ButtonGridProperty); }
set { SetValue(ButtonGridProperty, value); }
}
public static readonly DependencyProperty ButtonGridProperty =
DependencyProperty.Register("ButtonGrid", typeof(Grid), typeof(MyControl), new PropertyMetadata(new Grid()));
public MyControl()
{
InitializeComponent();
}
}
}
I tried many ways of making this "ButtonGrid"-value visible and working but still it doesn't. Any Ideas?
EDIT I can get the Grid in the codebehind with a simple getter. But its just not straight-forward to create stuff somewhere and THEN put them to the place I want them to be.