I am new to UWP and C# so i hope that somebody can help me. I am currently trying to make a custom control in UWP but got a problem. My idea is a button to change the theme of the application. For that i want to let the user of my custom control speicify which elements he want the background to change in the XAML-file.
It should look like this (Pseudocode):
<Grid x:Name="Grid1" Grid.Column="1" Background="Black">
<Button x:Name="Button1"/>
<local:ModeSelector Grid.Row="1">
<local:ModeSelector.Tools>
<Button1/>
<Grid1/>
...
</local:ModeSelector.Tools>
</local:ModeSelector>
</Grid>
My DependencyObject looks like this:
public List<Control> Tools
{
get { return (List<Control>)GetValue(ToolsProperty); }
set { SetValue(ToolsProperty, new List<Control>()); }
}
public static readonly DependencyProperty ToolsProperty =
DependencyProperty.Register("Tools", typeof(List<Control>), typeof(ModeSelector), new PropertyMetadata(new List<Control>()));
in my c# file i then have a list of controls from which i can change the backgroundcolor. In this example it is "Button1", "Grid1", ... . My question now how can i implement this list in my XAML file?
Thank you in advance
CodePudding user response:
I'm not an expert on this, but it sounds like what you're trying to do is apply customized themes.
I would give this article a read through: Custom Themes in UWP Application
And this video here: XAML Themes
CodePudding user response:
I'd suggest you use a list of string
instead of a list of Control
. I've tested the Control
type of list with binding, the databinding will throw exceptions even when you set the x:DataType as Control
. So you might need use the name of each control instead if you want to use binding to list all the Controls. Then when you select a control, you could find the control via its name. Like what is done here:https://stackoverflow.com/a/70210083/8354952