{"id":4547,"date":"2021-01-28T13:46:21","date_gmt":"2021-01-28T12:46:21","guid":{"rendered":"https:\/\/solidt.eu\/site\/?p=4547"},"modified":"2022-07-25T08:31:51","modified_gmt":"2022-07-25T07:31:51","slug":"c-xaml-nested-components","status":"publish","type":"post","link":"https:\/\/solidt.eu\/site\/c-xaml-nested-components\/","title":{"rendered":"C# XAML nested controls\/components"},"content":{"rendered":"\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"xml\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;UserControl x:Class=\"Views.Controls.FieldLabel\"\n             xmlns=\"http:\/\/schemas.microsoft.com\/winfx\/2006\/xaml\/presentation\"\n             xmlns:x=\"http:\/\/schemas.microsoft.com\/winfx\/2006\/xaml\"\n             xmlns:mc=\"http:\/\/schemas.openxmlformats.org\/markup-compatibility\/2006\" \n             xmlns:d=\"http:\/\/schemas.microsoft.com\/expression\/blend\/2008\"\n             mc:Ignorable=\"d\" \n             d:DesignHeight=\"450\" d:DesignWidth=\"800\" x:Name=\"Control\" VerticalAlignment=\"Stretch\" HorizontalAlignment=\"Stretch\">\n    &lt;Grid VerticalAlignment=\"Stretch\" HorizontalAlignment=\"Stretch\">\n        &lt;Grid.ColumnDefinitions>\n            &lt;ColumnDefinition Width=\"50*\" \/>\n            &lt;ColumnDefinition Width=\"50*\" \/>\n        &lt;\/Grid.ColumnDefinitions>\n        &lt;StackPanel Grid.Column=\"0\" Margin=\"0 5\">\n            &lt;Label Content=\"{Binding Label, ElementName=Control}\" FontWeight=\"Bold\"\/>\n        &lt;\/StackPanel>\n        &lt;StackPanel Grid.Column=\"1\" Margin=\"0 5\">\n            &lt;ContentPresenter Content=\"{Binding Editor, ElementName=Control}\" HorizontalAlignment=\"Stretch\" VerticalAlignment=\"Stretch\" \/>\n        &lt;\/StackPanel>\n    &lt;\/Grid>\n&lt;\/UserControl>\n<\/pre>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">using System.Windows;\nusing System.Windows.Controls;\n\nnamespace Views.Controls\n{\n    public partial class FieldLabel : UserControl\n    {\n        public static readonly DependencyProperty LabelProperty = DependencyProperty.Register(nameof(Label), typeof(string), typeof(FieldLabel), new PropertyMetadata(null));\n        public string Label\n        {\n            get => (string)GetValue(LabelProperty);\n            set => SetValue(LabelProperty, value);\n        }\n\n        public static readonly DependencyProperty EditorProperty = DependencyProperty.Register(nameof(Editor), typeof(Control), typeof(FieldLabel), new PropertyMetadata((Control)null));\n        public Control Editor\n        {\n            get => (Control)GetValue(EditorProperty);\n            set => SetValue(EditorProperty, value);\n        }\n\n        public FieldLabel()\n        {\n            InitializeComponent();\n        }\n    }\n}\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Usage<\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"xml\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;!-- xmlns:controls=\"clr-namespace:Views.Controls\" -->\n&lt;ScrollViewer VerticalScrollBarVisibility=\"Auto\" HorizontalAlignment=\"Stretch\" VerticalAlignment=\"Stretch\">\n    &lt;StackPanel Margin=\"15\" Orientation=\"Vertical\">\n        &lt;controls:FieldLabel Label=\"MyCombobox\">\n            &lt;controls:FieldLabel.Editor>\n                &lt;ComboBox>\n                    &lt;ComboBoxItem>Test 1&lt;\/ComboBoxItem>\n                    &lt;ComboBoxItem>Test 2&lt;\/ComboBoxItem>\n                    &lt;ComboBoxItem>Test 3&lt;\/ComboBoxItem>\n                &lt;\/ComboBox>\n            &lt;\/controls:FieldLabel.Editor>\n        &lt;\/controls:FieldLabel>\n        &lt;controls:FieldLabel Label=\"MyTextbox\">\n            &lt;controls:FieldLabel.Editor>\n                &lt;TextBox Text=\"MyValue\" \/>\n            &lt;\/controls:FieldLabel.Editor>\n        &lt;\/controls:FieldLabel>\n        &lt;controls:FieldLabel Label=\"MyDatePicker\">\n            &lt;controls:FieldLabel.Editor>\n                &lt;DatePicker \/>\n            &lt;\/controls:FieldLabel.Editor>\n        &lt;\/controls:FieldLabel>\n    &lt;\/StackPanel>\n&lt;\/ScrollViewer><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Usage<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[6,4,1],"tags":[],"class_list":["post-4547","post","type-post","status-publish","format-standard","hentry","category-dotnet","category-programming","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/4547","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/comments?post=4547"}],"version-history":[{"count":7,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/4547\/revisions"}],"predecessor-version":[{"id":4554,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/4547\/revisions\/4554"}],"wp:attachment":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/media?parent=4547"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/categories?post=4547"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/tags?post=4547"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}