{"id":3184,"date":"2020-04-03T12:32:55","date_gmt":"2020-04-03T10:32:55","guid":{"rendered":"http:\/\/www.capri-soft.de\/blog\/?p=3184"},"modified":"2020-04-03T12:32:55","modified_gmt":"2020-04-03T10:32:55","slug":"net-wpf-xaml-locations-to-place-and-change-wpf-styles","status":"publish","type":"post","link":"https:\/\/www.capri-soft.de\/blog\/?p=3184","title":{"rendered":".NET WPF : XAML locations to place and change WPF Styles"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Intention<\/h2>\n\n\n\n<p>Like in HTML\/CSS there are different source code locations where it is possible to apply appearance styles to WPF controls. In this article i want to make a really short summary of those points. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Approach<\/h2>\n\n\n\n<p>The following examples are showing the declaration places for styles in the order from local control styles to global application styles<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Location examples<\/h2>\n\n\n\n<p>App.xaml (global application wide styles)<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: xml; title: ; notranslate\" title=\"\">\n&lt;Application x:Class=&quot;WPFTutorial.App&quot;\n             xmlns=&quot;http:\/\/schemas.microsoft.com\/winfx\/2006\/xaml\/presentation&quot;\n             xmlns:x=&quot;http:\/\/schemas.microsoft.com\/winfx\/2006\/xaml&quot;\n             StartupUri=&quot;MainWindow.xaml&quot;&gt;\n    &lt;Application.Resources&gt;\n            &lt;Style TargetType=&quot;TextBlock&quot;&gt;\n                &lt;Setter Property=&quot;Foreground&quot; Value=&quot;#ff0000&quot; \/&gt;\n                &lt;Setter Property=&quot;FontSize&quot; Value=&quot;24&quot; \/&gt;\n            &lt;\/Style&gt;\n    &lt;\/Application.Resources&gt;\n&lt;\/Application&gt;\n\n<\/pre><\/div>\n\n\n<p>MainWindow.xaml (local hierarchical inheritance from the WPF DOM)<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: xml; title: ; notranslate\" title=\"\">\n&lt;Window x:Class=&quot;WPFTutorial.MainWindow&quot;\n        xmlns=&quot;http:\/\/schemas.microsoft.com\/winfx\/2006\/xaml\/presentation&quot;\n        xmlns:x=&quot;http:\/\/schemas.microsoft.com\/winfx\/2006\/xaml&quot;\n        Title=&quot;WPF Layoutmanager&quot; Height=&quot;322&quot; Width=&quot;528&quot;&gt;\n    &lt;Window.Resources&gt;\n        &lt;Style TargetType=&quot;TextBlock&quot;&gt;\n            &lt;!-- This sets all TextBlock FontSize Styles within the Grid --&gt;\n            &lt;Setter Property=&quot;FontSize&quot; Value=&quot;15&quot; \/&gt;\n            &lt;Setter Property=&quot;Foreground&quot; Value=&quot;red&quot; \/&gt;\n        &lt;\/Style&gt;\n        &lt;Style TargetType=&quot;TabControl&quot;&gt;\n            &lt;Setter Property=&quot;VerticalContentAlignment&quot; Value=&quot;Stretch&quot;\/&gt;\n            &lt;Setter Property=&quot;VerticalAlignment&quot; Value=&quot;Stretch&quot;\/&gt;\n        &lt;\/Style&gt;\n    &lt;\/Window.Resources&gt;\n    &lt;DockPanel&gt;\n        &lt;TextBlock DockPanel.Dock=&quot;Top&quot; VerticalAlignment=&quot;Center&quot; Text=&quot;Ein Dockpanel.Dock=Top ist das hier und TabControl als LastChild gestretcht&quot; \/&gt;\n        &lt;TabControl&gt;\n            &lt;TabItem Header=&quot;Grid&quot;&gt;\n                &lt;Grid&gt;\n                    &lt;Grid.Resources&gt;\n                        &lt;Style TargetType=&quot;TextBlock&quot;&gt;\n                            &lt;!-- This sets all TextBlock FontSize Styles within the Grid --&gt;\n                            &lt;Setter Property=&quot;FontSize&quot; Value=&quot;15&quot; \/&gt;\n                        &lt;\/Style&gt;\n                    &lt;\/Grid.Resources&gt;\n                    &lt;Grid.ColumnDefinitions&gt;\n                        &lt;ColumnDefinition Width=&quot;1*&quot; \/&gt;\n                        &lt;ColumnDefinition Width=&quot;1*&quot; \/&gt;\n                        &lt;ColumnDefinition Width=&quot;1*&quot; \/&gt;\n                    &lt;\/Grid.ColumnDefinitions&gt;\n                    &lt;Grid.RowDefinitions&gt;\n                        &lt;RowDefinition Height=&quot;1*&quot; \/&gt;\n                        &lt;RowDefinition Height=&quot;1*&quot; \/&gt;\n                        &lt;RowDefinition Height=&quot;1*&quot; \/&gt;\n                    &lt;\/Grid.RowDefinitions&gt;\n                    &lt;Button Width=&quot;140&quot; Height=&quot;50&quot; Click=&quot;Button_Click&quot;&gt;\n                        &lt;StackPanel Orientation=&quot;Horizontal&quot;&gt;\n                            &lt;Image Margin=&quot;10&quot;  Source=&quot;Images\/haken.png&quot; Stretch=&quot;UniformToFill&quot;\/&gt;\n                            &lt;TextBlock VerticalAlignment=&quot;Center&quot; Text=&quot;Play Sound&quot; \/&gt;\n                        &lt;\/StackPanel&gt;\n                    &lt;\/Button&gt;\n                    &lt;Button Grid.Column=&quot;1&quot; Grid.Row=&quot;2&quot; Width=&quot;140&quot; Height=&quot;50&quot; Click=&quot;Button_Click&quot;&gt;\n                        &lt;StackPanel Orientation=&quot;Horizontal&quot;&gt;\n                            &lt;Image Margin=&quot;10&quot;  Source=&quot;Images\/haken.png&quot; Stretch=&quot;UniformToFill&quot;\/&gt;\n                            &lt;TextBlock VerticalAlignment=&quot;Center&quot; Text=&quot;Play Sound&quot; \/&gt;\n                        &lt;\/StackPanel&gt;\n                    &lt;\/Button&gt;\n                    &lt;Button Grid.Column=&quot;2&quot; Grid.Row=&quot;1&quot; Width=&quot;140&quot; Height=&quot;50&quot; Click=&quot;Button_Click&quot;&gt;\n                        &lt;StackPanel Orientation=&quot;Horizontal&quot;&gt;\n                            &lt;Image Margin=&quot;10&quot;  Source=&quot;Images\/haken.png&quot; Stretch=&quot;UniformToFill&quot;\/&gt;\n                            &lt;TextBlock VerticalAlignment=&quot;Center&quot; Text=&quot;Play Sound&quot; &gt;\n                                &lt;TextBlock.Style&gt;\n                                    &lt;!-- Dieser Style gilt nur f\u00fcr den Textblock local und \u00fcberschreibt den GRID Style --&gt;\n                                    &lt;Style&gt;\n                                        &lt;Setter Property=&quot;TextBlock.FontSize&quot; Value=&quot;10&quot; \/&gt;\n                                        &lt;Setter Property=&quot;TextBlock.FontWeight&quot; Value=&quot;Bold&quot; \/&gt;\n                                        &lt;Setter Property=&quot;TextBlock.Foreground&quot; Value=&quot;#ff00ff&quot; \/&gt;\n                                    &lt;\/Style&gt;\n                                &lt;\/TextBlock.Style&gt;\n                            &lt;\/TextBlock&gt;\n                        &lt;\/StackPanel&gt;\n                    &lt;\/Button&gt;\n                &lt;\/Grid&gt;\n            &lt;\/TabItem&gt;\n            &lt;TabItem Header=&quot;StackPanel&quot;&gt;\n                &lt;StackPanel Orientation=&quot;Vertical&quot;&gt;\n                    &lt;TextBlock Text=&quot;Dummfug ersetzt Irrsinn&quot;\/&gt;\n                    &lt;TextBlock Text=&quot;Irrsinn ersetzt Dummfug&quot; \/&gt;\n                    &lt;TextBlock Text=&quot;Das letzte Child ist im Gegensatz zum Dockpanel nicht gestretcht&quot; &gt;\n                        &lt;TextBlock.Style&gt;\n                            &lt;Style&gt;\n                                &lt;Setter Property=&quot;TextBlock.Foreground&quot; Value=&quot;#ff00ff&quot; \/&gt;\n                            &lt;\/Style&gt;\n                        &lt;\/TextBlock.Style&gt;\n                    &lt;\/TextBlock&gt;\n                &lt;\/StackPanel&gt;\n            &lt;\/TabItem&gt;\n        &lt;\/TabControl&gt;\n    &lt;\/DockPanel&gt;\n&lt;\/Window&gt;\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"474\" height=\"253\" data-attachment-id=\"3185\" data-permalink=\"https:\/\/www.capri-soft.de\/blog\/?attachment_id=3185\" data-orig-file=\"https:\/\/i0.wp.com\/www.capri-soft.de\/blog\/wp-content\/uploads\/2020\/04\/image.png?fit=686%2C366&amp;ssl=1\" data-orig-size=\"686,366\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/www.capri-soft.de\/blog\/wp-content\/uploads\/2020\/04\/image.png?fit=474%2C253&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/www.capri-soft.de\/blog\/wp-content\/uploads\/2020\/04\/image.png?resize=474%2C253&#038;ssl=1\" alt=\"\" class=\"wp-image-3185\" srcset=\"https:\/\/i0.wp.com\/www.capri-soft.de\/blog\/wp-content\/uploads\/2020\/04\/image.png?w=686&amp;ssl=1 686w, https:\/\/i0.wp.com\/www.capri-soft.de\/blog\/wp-content\/uploads\/2020\/04\/image.png?resize=300%2C160&amp;ssl=1 300w\" sizes=\"auto, (max-width: 474px) 100vw, 474px\" \/><\/figure>\n<iframe src=\"http:\/\/www.facebook.com\/plugins\/like.php?href=https%3A%2F%2Fwww.capri-soft.de%2Fblog%2F%3Fp%3D3184&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light\" scrolling=\"no\" frameborder=\"0\" allowTransparency=\"true\" style=\"border:none; overflow:hidden; width:450px;margin-top:5px;\"><\/iframe>","protected":false},"excerpt":{"rendered":"<p>Intention Like in HTML\/CSS there are different source code locations where it is possible to apply appearance styles to WPF controls. In this article i want to make a really short summary of those points. Approach The following examples are showing the declaration places for styles in the order from local control styles to global &hellip; <a href=\"https:\/\/www.capri-soft.de\/blog\/?p=3184\" class=\"more-link\"><span class=\"screen-reader-text\">.NET WPF : XAML locations to place and change WPF Styles<\/span> weiterlesen <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[114],"tags":[117,118,116,115],"class_list":["post-3184","post","type-post","status-publish","format-standard","hentry","category-wpf-windows-presentation-foundation","tag-global","tag-local","tag-style","tag-wpf"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p4yGeN-Pm","jetpack_likes_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3184","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3184"}],"version-history":[{"count":1,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3184\/revisions"}],"predecessor-version":[{"id":3186,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3184\/revisions\/3186"}],"wp:attachment":[{"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3184"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3184"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3184"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}