Hi I want to do the following in xaml:
I have a property FocusTarget in my control class which I want to assign an UIElement from the current class. Is this possible in XAML?
<my:BaseControl x:Class="SectionControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
FocusTarget="myCtrl"> // this fails
..
<my:CodeBlockControl x:Name="myCtrl" />
..
</my:BaseControl>
UPDATE: I now implemented the property as dependency property but it seems that no assignment occures, although I assign it in XAML. But there is not compile nor runtime error:
in xaml:
FocusTarget="{Binding ElementName=myCtrl}"
in cs:
public static readonly DependencyProperty FocusTargetProperty;
static BaseControl()
{
FrameworkPropertyMetadata metadata = new FrameworkPropertyMetadata(null);
FocusTargetProperty = DependencyProperty.Register("FocusTarget", typeof(FrameworkElement), typeof(BaseControl), metadata, Validate);
}
public FrameworkElement FocusTarget
{
get { return GetValue(FocusTargetProperty)as FrameworkElement; }
set { SetValue(FocusTargetProperty, value); }
}