C # XAML WPF Use Parameters Before Render on UserControl

I am new to the C # world and have a question about using xaml parameters UserControl Objects.

I have defined UserControll "ImageButton" in my MainGrid / Main Window in xaml:

<local:ImageButton HorizontalAlignment="Left" Height="100" Margin="49,122,0,0" VerticalAlignment="Top" Width="100" sText="SomeText" sType="main_button" Source="Resources/main_button.png" />

      

On the other hand I have my ImageBButton.xmal.cs

public partial class ImageButton : UserControl
.....
public ImageSource Source
{
    get { 
        return (ImageSource)GetValue(SourceProperty); }
        set { SetValue(SourceProperty, value); }
    }
.....
public static readonly DependencyProperty SourceProperty = DependencyProperty.Register("Source", typeof(ImageSource), typeof(ImageButton), new UIPropertyMetadata(default(ImageSource)));
.....
public ImageButton()
{
    InitializeComponent();
}
.....

      

Now I would like to know at what point I have access via the parameter values ​​that I have defined in the xaml.

I have tried several methods (including the constructor itself), but I am getting an empty value in C # code. Since I have tried several methods now, I now use the OnRender method - in this method I can access my parameters from xaml.

But I'm really not sure if this is the right way.

Can anyone know another method before the Usercontroll is drawn, where I can access the xaml parametervalues ​​and handle some stuff?

kindly greet

+3


source to share


1 answer


Property values ​​declared in your own Xaml UserControl will be processed in InitializeComponent()

. The values ​​provided on sites using your UserControl's Xaml will be available after promotion Initialized

.



The bindings are slightly different; the bindings will be applied and ready to accept values ​​based on the rules above, but the original values ​​cannot be passed to the targets until the dispatcher can handle the priority items DataBind

. This will happen by the time the control Loaded

.

+2


source







All Articles