Custom list giving fill in Xaml – WPF

Recently time I wanted to create UserControl with list property. What’s more I wanted to have possibility add elements in Xaml.
It is the solution snippet code:

 

public List<SchoolTypeEnum> Types 

{ 

    get 

    { 

        return 

        (List<SchoolTypeEnum>)(GetValue(SchoolChooser.TypesProperty)); 

    }   

}

 

public static List<SchoolTypeEnum> GetTypes(DependencyObject obj) 

{ 

    return (List<SchoolTypeEnum>)obj.GetValue(TypesProperty); 

}

public static void SetTypes(DependencyObject obj, List<SchoolTypeEnum> value) 

{ 

    obj.SetValue(TypesProperty, value);

}

// Using a DependencyProperty as the backing store for Types. This enables animation, styling, binding, etc... public static readonly 

DependencyProperty TypesProperty = 

    DependencyProperty.RegisterAttached("Types", 

    typeof(List<SchoolTypeEnum>), typeof(SchoolChooser), new 

    UIPropertyMetadata(new List<SchoolTypeEnum>()));

 

 

<c:SchoolChooser > 

    <c:SchoolChooser.Types> 

        <e:SchoolTypeEnum>IZ</e:SchoolTypeEnum> 

        <e:SchoolTypeEnum>UZ</e:SchoolTypeEnum> 

    </c:SchoolChooser.Types> 

</c:SchoolChooser>

  • Share/Bookmark

Tags: , ,

Leave a Reply