Note that there are some explanatory texts on larger screens.

plurals
  1. POUse Dependency Properties for global properties
    primarykey
    data
    text
    <p>I am new to wpf. I have been reading a lot about wpf and dependency properties. My understanding of Dependency Properties is to bind properties to xaml (xaml being the target). I have envisioned a program which a single configuration window would control all visual elements of the rest of the program (font, font size, colors, etc).</p> <p>In my first attempt, I created a separate window that would contain all the different configuration options. This failed because I was unable to figure out how to use the dependency properties in separate XAML files.</p> <p>Also, the dependency properties can only be registered in a class that implements directly or indeirectly the DependecyObject class. How do I know which wpf objects implement it? It appears the window does not, but I could be wrong. My second attempt was this, to register the dependencies in the top window, so the whole visual tree would have access to it. I had exceptions being thrown and the only thing I could thing of was that the window does not implement to DependencyObject. (I could be mistaken, and the visual tree thing is still sort of a mystery to me. I am learning though)</p> <p>So now I'm at a loss. Is what I am attempting even possible? The whole purpose of this project was to help me learn wpf and now I'm wondering if I should lower my expectations of what I can accomplish with wpf. </p> <p><strong>Edit:</strong> </p> <blockquote> <p>What kind of exception? What are you trying to do? Could you paste some code?</p> </blockquote> <pre><code>public partial class MainWindow : Window { public Color BackColor { get { return (Color)GetValue(BackColorProperty); } set { SetValue(BackColorProperty, value); } } public static readonly DependencyProperty BackColorProperty = DependencyProperty.Register("BackColor",typeof(Color),typeof(MainWindow), new UIPropertyMetadata(0)); </code></pre> <p>It appears that <code>Color</code> was causing the exception. I changed it to <code>int</code> and no exception was thrown. So are primitive types only able to be registered?</p> <blockquote> <p>WPF is a framework to help you bulit really good looking apps (it includes also Printing etc.) What are you trying to do? Should it be a part of Visual Tree?</p> </blockquote> <p>Again, this project was only meant to get me to learn WPF. My idea was to create a main UI with different pages. A configuration button would bring up a window with options to change font, fontsize, background color, etc. These changes would be applied in the main UI as the user made the changes. My issue has been how do I access those dependency properties outside of the configuration class where they were registered? How do I have one window that can has slider and combo boxes, and any other class can access those configuration settings?</p> <p>Put simply, I would like that a single configuration (fonts and colors) be somehow inherited by all UIs. And that that configuration can be changed and seen by the user.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload