<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Biggle&#039;s Blog &#187; XAML</title>
	<atom:link href="http://www.biggle.de/blog/category/markup/xaml-markup/feed" rel="self" type="application/rss+xml" />
	<link>http://www.biggle.de/blog</link>
	<description>Web- und Software Development</description>
	<lastBuildDate>Sat, 31 Jul 2010 14:59:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>ComboBox an ObjectDataProvider binden</title>
		<link>http://www.biggle.de/blog/combobox-an-objectprovider-binden</link>
		<comments>http://www.biggle.de/blog/combobox-an-objectprovider-binden#comments</comments>
		<pubDate>Wed, 05 May 2010 14:27:32 +0000</pubDate>
		<dc:creator>Mario Priebe</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[XAML]]></category>
		<category><![CDATA[MVVM]]></category>

		<guid isPermaLink="false">http://www.biggle.de/blog/?p=4564</guid>
		<description><![CDATA[Will man eine ComBox über das Binding befüllen, kann man dazu den ObjectDataProvider verwenden. Ich  deklariere dazu eine statische Klasse namens Collections, in der eine oder mehrere Aufzählungen implementiert werden. In meinem Beispiel verwende ich die die Aufzählung GetAnreden Diese Methode ist statisch und  hat ein Dictionary als Rückgabewert. 1 2 3 4 5 6 [...]]]></description>
			<content:encoded><![CDATA[<p>Will man eine ComBox über das Binding befüllen, kann man dazu den ObjectDataProvider verwenden.</p>
<p>Ich  deklariere dazu eine statische Klasse namens Collections, in der eine oder mehrere Aufzählungen implementiert werden. In meinem Beispiel verwende ich die die Aufzählung GetAnreden</p>
<p>Diese Methode ist statisch und  hat ein Dictionary <EnumTyp, String> als Rückgabewert.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/// &lt;summary&gt;</span>
<span style="color: #666666; font-style: italic;">/// Stellt für den ObjectProvider im XAML die ComboBoxItems zur Verfuegung</span>
<span style="color: #666666; font-style: italic;">/// &lt;/summary&gt;</span>
<span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000000; font-weight: bold;">class</span> Collections
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> static Dictionary<span style="color: #339933;">&lt;</span>Anrede<span style="color: #339933;">,</span> string<span style="color: #339933;">&gt;</span> GetAnreden<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        Dictionary<span style="color: #339933;">&lt;</span>Anrede<span style="color: #339933;">,</span> string<span style="color: #339933;">&gt;</span> choices <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Dictionary<span style="color: #339933;">&lt;</span>Anrede<span style="color: #339933;">,</span> string<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        choices<span style="color: #339933;">.</span>Add<span style="color: #009900;">&#40;</span>Anrede<span style="color: #339933;">.</span>OhneAnrede<span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Ohne Anrede&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        choices<span style="color: #339933;">.</span>Add<span style="color: #009900;">&#40;</span>Anrede<span style="color: #339933;">.</span>Herr<span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Herr&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        choices<span style="color: #339933;">.</span>Add<span style="color: #009900;">&#40;</span>Anrede<span style="color: #339933;">.</span>Frau<span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Frau&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        choices<span style="color: #339933;">.</span>Add<span style="color: #009900;">&#40;</span>Anrede<span style="color: #339933;">.</span>Fraeulein<span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Fräulein&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        choices<span style="color: #339933;">.</span>Add<span style="color: #009900;">&#40;</span>Anrede<span style="color: #339933;">.</span>HerrUndFrau<span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Eheleute&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        choices<span style="color: #339933;">.</span>Add<span style="color: #009900;">&#40;</span>Anrede<span style="color: #339933;">.</span>Firma<span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Firma&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> choices<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Im XAML definiere ich als Resource den ObjectDataProvider.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>UserControl<span style="color: #339933;">.</span>Resources<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>ObjectDataProvider x<span style="color: #339933;">:</span><span style="color: #990000;">Key</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;GetAnreden&quot;</span> ObjectType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{x:Type local:Collections}&quot;</span> MethodName<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;GetAnreden&quot;</span><span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;/</span>UserControl<span style="color: #339933;">.</span>Resources<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>Und verwenden kann man den ObjectDataProvider zum Beispiel in einer ComboBox. Hier binde ich die ItemSource an den o.g. Provider. Mit DisplayMemberPath und SelectedValuePath lege ich den Key und den Value fest.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>ComboBox SelectedValue<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{Binding Anrede}&quot;</span>
    ItemsSource<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{Binding Source={StaticResource GetAnreden}}&quot;</span>
    DisplayMemberPath<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Value&quot;</span>
    SelectedValuePath<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Key&quot;</span><span style="color: #339933;">/&gt;</span></pre></td></tr></table></div>

<p>Über den DataContext muss nun noch das ViewModelProperty gebunden werden, welche den Wert speichern soll, in diesen Beispiel mache ich das im darüber liegenden StackPanel.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>StackPanel DataContext<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{Binding Person}&quot;</span> <span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>ComboBox SelectedValue<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{Binding Anrede}&quot;</span>
    ItemsSource<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{Binding Source={StaticResource GetAnreden}}&quot;</span>
    DisplayMemberPath<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Value&quot;</span>
    SelectedValuePath<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Key&quot;</span><span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;/</span>StackPanel<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>Das wars auch schon,</p>
<p>Viel Spass beim entwickeln : )</p>
<p><br class="spacer_" /></p>
<hr /><p style="float:right; font-size:0.9em;">Dieser Beitrag stammt von <a href="http://www.biggle.de">Mario Priebe</a>.</p><h2  class="related_post_title">Ähnliche Beiträge</h2><ul class="related_post"><li>22. Juli 2009 -- <a href="http://www.biggle.de/blog/cal-anwendung-in-3-minuten" title="CAL Anwendung in 3 Minuten">CAL Anwendung in 3 Minuten</a></li><li>16. Juli 2009 -- <a href="http://www.biggle.de/blog/menuitems-aus-xml-auslesen-und-binden-wpf-mvvm" title="MenuItems aus XML auslesen und binden &#8211; WPF / MVVM ">MenuItems aus XML auslesen und binden &#8211; WPF / MVVM </a></li><li>25. März 2010 -- <a href="http://www.biggle.de/blog/tabcontrol-hoehe-100percent" title="TabControl-Höhe 100%">TabControl-Höhe 100%</a></li><li>5. März 2010 -- <a href="http://www.biggle.de/blog/navigation-paging-in-wpf" title="Navigation / Paging in WPF">Navigation / Paging in WPF</a></li><li>16. Dezember 2009 -- <a href="http://www.biggle.de/blog/textbox-passwordbox-gemeinsamer-style-xaml" title="TextBox und PasswordBox mit gemeinsamen Style">TextBox und PasswordBox mit gemeinsamen Style</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.biggle.de/blog/combobox-an-objectprovider-binden/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Das WPF Control &#8220;Popup&#8221; &#8211; HowTo</title>
		<link>http://www.biggle.de/blog/das-wpf-control-popup-howto</link>
		<comments>http://www.biggle.de/blog/das-wpf-control-popup-howto#comments</comments>
		<pubDate>Tue, 13 Apr 2010 15:35:00 +0000</pubDate>
		<dc:creator>Mario Priebe</dc:creator>
				<category><![CDATA[CSharp]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[XAML]]></category>
		<category><![CDATA[HowTo]]></category>
		<category><![CDATA[WPFControls]]></category>

		<guid isPermaLink="false">http://www.biggle.de/blog/?p=4446</guid>
		<description><![CDATA[Das WPF Control Popup kann ein eigenständiges Fenster in einer WPF Applikation darstellen und wie ein Tooltip beim Überfahren von Elementen angezeigt werden. Ein Popup kann als Kindelement ein weiteres UIElement aufnehmen, was so einem weiteren Design des Popups, nichts im Wege stehen sollte. Die Position kann relativ zum Element oder zur Applikation geöffnet werden. [...]]]></description>
			<content:encoded><![CDATA[<p>Das WPF Control Popup kann ein eigenständiges Fenster in einer WPF Applikation darstellen und wie ein Tooltip beim Überfahren von Elementen angezeigt werden. Ein Popup kann als Kindelement ein weiteres UIElement aufnehmen, was so einem weiteren Design des Popups, nichts im Wege stehen sollte.</p>
<p>Die Position kann relativ zum Element oder zur Applikation geöffnet werden. Das Popup verhält sich auch wie ein eigenständiges Fenster, das heisst wird die Mainapplikation verschoben, bleibt das Popup an der letzten Position stehen.</p>
<p><a href="http://www.biggle.de/blog/wp-content/uploads/2010/04/popup.jpg"><img src="http://www.biggle.de/blog/wp-content/uploads/2010/04/popup.jpg" alt="" title="popup" width="426" height="345" class="alignnone size-full wp-image-4457" /></a></p>
<p>Ein Popup wird nicht wie ein Tooltip automatisch geöffnet, sondern muss explizit durch dessen Eigenschaft IsOpen geöffnet und geschlossen werden.</p>
<p>Die Anzeigeposition wird durch die Placement-Eigenschaften festgelegt. Zu welchem Element sich die Placements beziehen, legt man an der Property PlacementTarget fest. Die X und die Y Koordinate HorizontalOffset und VertracalOffset setzt man bei einem gewählten &#8220;Absolute&#8221; oder &#8220;Relative&#8221; Placement aus der Enumeration PlacementMode.</p>
<p>Weitere Eigenschaften an dem Control sind PopupAnimation und AllowsTransparency. Will man ein Popup animieren (Fade, None, Scroll, Slide) muss AllowsTransparency auf true gesetzt werden.</p>
<p>Das folgende Beispiel soll das gesagte etwas verdeutlichen. Hier beziehe ich mein Placement relativ zur Applikation(window), den Bezug stellt man über ElementName her.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>Window x<span style="color: #339933;">:</span><span style="color: #000000; font-weight: bold;">Class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;PopupHowTo.Window1&quot;</span>
    xmlns<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;</span>
    xmlns<span style="color: #339933;">:</span>x<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;</span>
    Title<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Window1&quot;</span> Height<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;300&quot;</span> Width<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;300&quot;</span> Name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;myWindow&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>StackPanel HorizontalAlignment<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Left&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>TextBox Width<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;100&quot;</span> Name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;txtBox&quot;</span> MouseEnter<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;txtBox_MouseEnter&quot;</span> MouseLeave<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;txtBox_MouseLeave&quot;</span> <span style="color: #339933;">/&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>Popup Name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;popUp&quot;</span> PlacementTarget<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{Binding ElementName=myWindow}&quot;</span> Placement<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Relative&quot;</span> VerticalOffset<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;30&quot;</span> HorizontalOffset<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;100&quot;</span>
   PopupAnimation<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Slide&quot;</span> AllowsTransparency<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;True&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>Popup<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;/</span>StackPanel<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>Window<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>CodeBehind</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> partial <span style="color: #000000; font-weight: bold;">class</span> Window1 <span style="color: #339933;">:</span> Window
<span style="color: #009900;">&#123;</span>
MyUserControl uc<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">public</span> Window1<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    InitializeComponent<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    Loaded <span style="color: #339933;">+=</span> <span style="color: #000000; font-weight: bold;">new</span> RoutedEventHandler<span style="color: #009900;">&#40;</span>Window1_Loaded<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
void Window1_Loaded<span style="color: #009900;">&#40;</span>object sender<span style="color: #339933;">,</span> RoutedEventArgs e<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    uc <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MyUserControl<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    popUp<span style="color: #339933;">.</span>Child <span style="color: #339933;">=</span> uc<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">private</span> void txtBox_MouseEnter<span style="color: #009900;">&#40;</span>object sender<span style="color: #339933;">,</span> MouseEventArgs e<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    uc<span style="color: #339933;">.</span>HelpText <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Ich bin ein Hilfetext für eine TextBox&quot;</span><span style="color: #339933;">;</span>
    popUp<span style="color: #339933;">.</span>IsOpen <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">private</span> void txtBox_MouseLeave<span style="color: #009900;">&#40;</span>object sender<span style="color: #339933;">,</span> MouseEventArgs e<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    popUp<span style="color: #339933;">.</span>IsOpen <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>HelpText ist ein ViewModelProperty in MyUserControl.</p>
<p>Viel Spass beim entwickeln : )</p>
<p><br class="spacer_" /></p>
<hr /><p style="float:right; font-size:0.9em;">Dieser Beitrag stammt von <a href="http://www.biggle.de">Mario Priebe</a>.</p><h2  class="related_post_title">Ähnliche Beiträge</h2><ul class="related_post"><li>7. April 2010 -- <a href="http://www.biggle.de/blog/wcfservice-testen" title="WCFService testen">WCFService testen</a></li><li>27. November 2009 -- <a href="http://www.biggle.de/blog/aufzaehlungen-speichern" title="Aufzählungen speichern &#8211; C# Quicky">Aufzählungen speichern &#8211; C# Quicky</a></li><li>18. November 2009 -- <a href="http://www.biggle.de/blog/php-entwicklungsumgebung-auf-windows" title="PHP Entwicklungsumgebung unter Windows">PHP Entwicklungsumgebung unter Windows</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.biggle.de/blog/das-wpf-control-popup-howto/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TabControl-Höhe 100%</title>
		<link>http://www.biggle.de/blog/tabcontrol-hoehe-100percent</link>
		<comments>http://www.biggle.de/blog/tabcontrol-hoehe-100percent#comments</comments>
		<pubDate>Thu, 25 Mar 2010 08:57:11 +0000</pubDate>
		<dc:creator>Mario Priebe</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[XAML]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://www.biggle.de/blog/?p=4244</guid>
		<description><![CDATA[Wenn man ein TabControl in einem StackPanel plaziert, erbt das TabControl so auch die Höhe von dem Element StackPanel. Das kann negative Auswirkung haben: Um das Problem zu beheben muss man das StackPanel dazu bewegen sich in Höhe anzupassen, ein einfaches Height auf ein StackPanel bringt leider nichts. Man muss das innere Element, also das [...]]]></description>
			<content:encoded><![CDATA[<p>Wenn man ein TabControl in einem StackPanel plaziert, erbt das TabControl so auch die Höhe von dem Element StackPanel. Das kann negative Auswirkung haben:</p>
<p><a href="http://www.biggle.de/blog/wp-content/uploads/2010/03/tabcontrolfail.jpg"><img class="alignnone size-full wp-image-4245" title="tabcontrolfail" src="http://www.biggle.de/blog/wp-content/uploads/2010/03/tabcontrolfail.jpg" alt="" width="299" height="298" /></a></p>
<p>Um das Problem zu beheben muss man das StackPanel dazu bewegen sich in Höhe anzupassen, ein einfaches Height auf ein StackPanel bringt leider nichts. Man muss das innere Element, also das TabControl dazu bewegen das StackPanel zu vergrössern. Also muss man am TabControl die Höhe setzen. Soweit klar. Ich kann hier einen festen Wert definieren. Nun aber möchte ich das Ganze ja auch skalierbar umsetzen.</p>
<p>Dazu kann ich mir das darüberliegende Element holen, welches eine Höhe definiert. In meinem Beispiel ist das, das Window. Ich binde also die Höhe meines TabControls mit FindAncestor an die Höhe des Window:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>Window x<span style="color: #339933;">:</span><span style="color: #000000; font-weight: bold;">Class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;FindAncestor.Window1&quot;</span>
    xmlns<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;</span>
    xmlns<span style="color: #339933;">:</span>x<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;</span>
    Title<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Window1&quot;</span> Height<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;300&quot;</span> Width<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;300&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
	<span style="color: #339933;">&lt;</span>StackPanel<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span>TabControl Background<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;AliceBlue&quot;</span> Height<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=ActualHeight}&quot;</span><span style="color: #339933;">&gt;</span>
			<span style="color: #339933;">&lt;</span>TabItem <span style="color: #990000;">Header</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Test&quot;</span> Background<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;AliceBlue&quot;</span> <span style="color: #339933;">/&gt;</span>
		<span style="color: #339933;">&lt;/</span>TabControl<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;/</span>StackPanel<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;/</span>Window<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>Voila und der gewünschte Effekt wird erreicht.</p>
<p><a href="http://www.biggle.de/blog/wp-content/uploads/2010/03/tabcontrol.jpg"><img class="alignnone size-full wp-image-4246" title="tabcontrol" src="http://www.biggle.de/blog/wp-content/uploads/2010/03/tabcontrol.jpg" alt="" width="297" height="299" /></a></p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<hr /><p style="float:right; font-size:0.9em;">Dieser Beitrag stammt von <a href="http://www.biggle.de">Mario Priebe</a>.</p><h2  class="related_post_title">Ähnliche Beiträge</h2><ul class="related_post"><li>5. Mai 2010 -- <a href="http://www.biggle.de/blog/combobox-an-objectprovider-binden" title="ComboBox an ObjectDataProvider binden">ComboBox an ObjectDataProvider binden</a></li><li>5. März 2010 -- <a href="http://www.biggle.de/blog/navigation-paging-in-wpf" title="Navigation / Paging in WPF">Navigation / Paging in WPF</a></li><li>16. Dezember 2009 -- <a href="http://www.biggle.de/blog/textbox-passwordbox-gemeinsamer-style-xaml" title="TextBox und PasswordBox mit gemeinsamen Style">TextBox und PasswordBox mit gemeinsamen Style</a></li><li>25. November 2009 -- <a href="http://www.biggle.de/blog/mulitline-textbox-xaml-quicky" title="Multiline TextBox &#8211; XAML Quicky">Multiline TextBox &#8211; XAML Quicky</a></li><li>20. Oktober 2009 -- <a href="http://www.biggle.de/blog/note-multiple-styles-in-wpf" title="Note: Multiple Styles in WPF">Note: Multiple Styles in WPF</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.biggle.de/blog/tabcontrol-hoehe-100percent/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Navigation / Paging in WPF</title>
		<link>http://www.biggle.de/blog/navigation-paging-in-wpf</link>
		<comments>http://www.biggle.de/blog/navigation-paging-in-wpf#comments</comments>
		<pubDate>Fri, 05 Mar 2010 13:12:28 +0000</pubDate>
		<dc:creator>Mario Priebe</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[MarkUp]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[XAML]]></category>
		<category><![CDATA[Navigation]]></category>
		<category><![CDATA[Paging]]></category>

		<guid isPermaLink="false">http://www.biggle.de/blog/?p=4025</guid>
		<description><![CDATA[Es gibt so einige Ansätze wie man in einer WPF Applikation navigieren kann. Im kommenden Beispiel zeige ich eine Möglichkeit wie man recht einfach neue Seiten im Menue hinzufügen und darstellen kann. Ziel ist es, im MainWindow (Shell) ein Menue hinzuzufügen und die entsprechenden Pages unterhalb dieses anzuzeigen. Ich verwende in diesem HowTo ein TabControl, [...]]]></description>
			<content:encoded><![CDATA[<p>Es gibt so einige Ansätze wie man in einer WPF Applikation navigieren kann. Im kommenden Beispiel zeige ich eine Möglichkeit wie man recht einfach neue Seiten im Menue hinzufügen und darstellen kann.</p>
<p>Ziel ist es, im MainWindow (Shell) ein Menue hinzuzufügen und die entsprechenden Pages unterhalb dieses anzuzeigen.</p>
<p>Ich verwende in diesem HowTo ein TabControl, ein StackPanel ein Menu und MenuItems.</p>
<p><strong>Umsetzung:</strong></p>
<p>Zuvor definiere ich einen Style in der Shell (Windows.xaml), welcher das Element vom Typ TabControl überschreibt:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>Window<span style="color: #339933;">.</span>Resources<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>Style TargetType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;TabControl&quot;</span> x<span style="color: #339933;">:</span><span style="color: #990000;">Key</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;pagingStyle&quot;</span><span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span>Setter Property<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Template&quot;</span><span style="color: #339933;">&gt;</span>
			<span style="color: #339933;">&lt;</span>Setter<span style="color: #339933;">.</span>Value<span style="color: #339933;">&gt;</span>
				<span style="color: #339933;">&lt;</span>ControlTemplate TargetType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{x:Type TabControl}&quot;</span><span style="color: #339933;">&gt;</span>
					<span style="color: #339933;">&lt;</span>Grid<span style="color: #339933;">&gt;</span>
						<span style="color: #339933;">&lt;</span>Border Background<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Transparent&quot;</span><span style="color: #339933;">&gt;</span>
							<span style="color: #339933;">&lt;</span>ContentPresenter x<span style="color: #339933;">:</span>Name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;PART_SelectedContentHost&quot;</span> Margin<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{TemplateBinding Padding}&quot;</span>
                              SnapsToDevicePixels<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{TemplateBinding SnapsToDevicePixels}&quot;</span>
                              ContentSource<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;SelectedContent&quot;</span> <span style="color: #339933;">/&gt;</span>
						<span style="color: #339933;">&lt;/</span>Border<span style="color: #339933;">&gt;</span>
						<span style="color: #339933;">&lt;</span>TabPanel IsItemsHost<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;True&quot;</span> Visibility<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Hidden&quot;</span> <span style="color: #339933;">/&gt;</span>
					<span style="color: #339933;">&lt;/</span>Grid<span style="color: #339933;">&gt;</span>
				<span style="color: #339933;">&lt;/</span>ControlTemplate<span style="color: #339933;">&gt;</span>
			<span style="color: #339933;">&lt;/</span>Setter<span style="color: #339933;">.</span>Value<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;/</span>Setter<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;/</span>Style<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>Window<span style="color: #339933;">.</span>Resources<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>Weiter lege ich in der Shell (Windows.xaml) ein CommandBinding fest:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>Window<span style="color: #339933;">.</span>CommandBindings<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>CommandBinding Command<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;GoToPage&quot;</span> Executed<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;OnGoToPage&quot;</span> <span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;/</span>Window<span style="color: #339933;">.</span>CommandBindings<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>Und dargestellt wird das Ganze dann in einem StackPanel (Orientation Horizontal), welches ein Menue und ein TabControl enthält. Im TabControl zeigen wir später dann die Pages an.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>StackPanel<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>Menu<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span>MenuItem <span style="color: #990000;">Header</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Pages&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
		<span style="color: #339933;">&lt;/</span>MenuItem<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;/</span>Menu<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>TabControl Style<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{StaticResource pagingStyle}&quot;</span> SelectedIndex<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;0&quot;</span>  x<span style="color: #339933;">:</span>Name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Pages&quot;</span> <span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;/</span>StackPanel<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>Wechseln wir nun zum Code-Behind der Windows.xaml (Shell) und schreiben die Methode OnGoToPage(), welche in den CommandBindings definiert wurde:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> void OnGoToPage<span style="color: #009900;">&#40;</span>object sender<span style="color: #339933;">,</span> ExecutedRoutedEventArgs e<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>e<span style="color: #339933;">.</span>Parameter <span style="color: #339933;">!=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
        Pages<span style="color: #339933;">.</span>SelectedIndex <span style="color: #339933;">=</span> Pages<span style="color: #339933;">.</span>SelectedIndex <span style="color: #339933;">&lt;</span> Pages<span style="color: #339933;">.</span>Items<span style="color: #339933;">.</span><span style="color: #990000;">Count</span> ? int<span style="color: #339933;">.</span>Parse<span style="color: #009900;">&#40;</span>e<span style="color: #339933;">.</span>Parameter<span style="color: #339933;">.</span>ToString<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span> <span style="color: #339933;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Weiter abonnieren wir das LoadedEvent im Konstruktor um hier später die entsprechenden Pages in der TabControl-Collection hinzuzufügen.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> Window1<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    InitializeComponent<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    Loaded <span style="color: #339933;">+=</span> Window1_Loaded<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Nun lege ich eine neue Klasse namens BasePage an. In dieser Klasse definieren wir das &#8220;Masterlayout&#8221; der Pages. Man kann das zwar auch in einem Style definieren, jedoch in diesem Beispiel mache ich das direkt  in der Klasse. dazu schreib ich in den Konstruktor:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> BasePage<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    this<span style="color: #339933;">.</span>Height <span style="color: #339933;">=</span> <span style="color: #cc66cc;">250</span><span style="color: #339933;">;</span>
    this<span style="color: #339933;">.</span>Background <span style="color: #339933;">=</span> Brushes<span style="color: #339933;">.</span>AliceBlue<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Die Basis ist damit vorerst fertig &#8211; &#8220;vorerst&#8221; deshalb, weil hier später grundlegende Einstellungen vorgenommen werden können, aber für dieses Beispiel erstmal nicht relevant. Nun muss man nur noch die einzelnen Pages erstellen und der MenuCollection (Shell) die Pages hinzufügen. </p>
<p>Die <strong>UserControls</strong> die wir nun anlegen, erben von unserer Basisklasse BasePage. Dazu im XAML des jeweiligen UserControls das UserControl gegen Pages:BasePage und im Code-behind das UserControl gegen BasePage austauschen.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>Pages<span style="color: #339933;">:</span>BasePage x<span style="color: #339933;">:</span><span style="color: #000000; font-weight: bold;">Class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;NavigateWpfApplication.Pages.Page1&quot;</span>
    xmlns<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;</span>
    xmlns<span style="color: #339933;">:</span>x<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;</span>
    xmlns<span style="color: #339933;">:</span>Pages<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;clr-namespace:NavigateWpfApplication.Pages&quot;</span><span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>Grid<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span>TextBlock Text<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Hello from Page 1&quot;</span> <span style="color: #339933;">/&gt;</span>
	<span style="color: #339933;">&lt;/</span>Grid<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>Pages<span style="color: #339933;">:</span>BasePage<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> partial <span style="color: #000000; font-weight: bold;">class</span> Page1 <span style="color: #339933;">:</span> BasePage
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> Page1<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        InitializeComponent<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Zum Schluss nun die MenuItems in der Shell hinzufügen:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>MenuItem <span style="color: #990000;">Header</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Pages&quot;</span><span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>MenuItem <span style="color: #990000;">Header</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Page1&quot;</span> Command<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;GoToPage&quot;</span> CommandParameter<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;1&quot;</span> <span style="color: #339933;">/&gt;</span>
	<span style="color: #339933;">&lt;</span>MenuItem <span style="color: #990000;">Header</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Page2&quot;</span> Command<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;GoToPage&quot;</span> CommandParameter<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;2&quot;</span> <span style="color: #339933;">/&gt;</span>
	<span style="color: #339933;">&lt;</span>MenuItem <span style="color: #990000;">Header</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Page3&quot;</span> Command<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;GoToPage&quot;</span> CommandParameter<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;3&quot;</span> <span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;/</span>MenuItem<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>und im LoadedEvent der Shell die Pages:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">void Window1_Loaded<span style="color: #009900;">&#40;</span>object sender<span style="color: #339933;">,</span> RoutedEventArgs e<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    this<span style="color: #339933;">.</span>Pages<span style="color: #339933;">.</span>Items<span style="color: #339933;">.</span>Add<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Page1<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    this<span style="color: #339933;">.</span>Pages<span style="color: #339933;">.</span>Items<span style="color: #339933;">.</span>Add<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Page2<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    this<span style="color: #339933;">.</span>Pages<span style="color: #339933;">.</span>Items<span style="color: #339933;">.</span>Add<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Page3<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Et Voila, das wars auch schon,</p>
<p><a href="http://www.biggle.de/blog/wp-content/uploads/2010/03/pages.jpg"><img src="http://www.biggle.de/blog/wp-content/uploads/2010/03/pages.jpg" alt="" title="pages" width="260" height="290" class="alignnone size-full wp-image-4036" /></a></p>
<p>Viel Spaß beim entwickeln : )</p>
<hr /><p style="float:right; font-size:0.9em;">Dieser Beitrag stammt von <a href="http://www.biggle.de">Mario Priebe</a>.</p><h2  class="related_post_title">Ähnliche Beiträge</h2><ul class="related_post"><li>5. Mai 2010 -- <a href="http://www.biggle.de/blog/combobox-an-objectprovider-binden" title="ComboBox an ObjectDataProvider binden">ComboBox an ObjectDataProvider binden</a></li><li>25. März 2010 -- <a href="http://www.biggle.de/blog/tabcontrol-hoehe-100percent" title="TabControl-Höhe 100%">TabControl-Höhe 100%</a></li><li>16. Dezember 2009 -- <a href="http://www.biggle.de/blog/textbox-passwordbox-gemeinsamer-style-xaml" title="TextBox und PasswordBox mit gemeinsamen Style">TextBox und PasswordBox mit gemeinsamen Style</a></li><li>25. November 2009 -- <a href="http://www.biggle.de/blog/mulitline-textbox-xaml-quicky" title="Multiline TextBox &#8211; XAML Quicky">Multiline TextBox &#8211; XAML Quicky</a></li><li>20. Oktober 2009 -- <a href="http://www.biggle.de/blog/note-multiple-styles-in-wpf" title="Note: Multiple Styles in WPF">Note: Multiple Styles in WPF</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.biggle.de/blog/navigation-paging-in-wpf/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dynamisches Applikations Icon &#8211; XAML Quicky</title>
		<link>http://www.biggle.de/blog/dynamisches-applikations-icon-xaml</link>
		<comments>http://www.biggle.de/blog/dynamisches-applikations-icon-xaml#comments</comments>
		<pubDate>Sat, 02 Jan 2010 04:28:49 +0000</pubDate>
		<dc:creator>Mario Priebe</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[MarkUp]]></category>
		<category><![CDATA[XAML]]></category>
		<category><![CDATA[Quicky]]></category>
		<category><![CDATA[Styling]]></category>

		<guid isPermaLink="false">http://www.biggle.de/blog/?p=3590</guid>
		<description><![CDATA[Es ist möglich in einer WPF Applikation das Icon dynamisch festzulegen. Das hat den Hintergrund, dass z.B. wenn die Applikation gerade eine Aufgabe erledigt, so der Anwender über das Icon auf den Status aufmerksam gemacht wird (blur, SandUhr o.ä.). Das selbe gilt natürlich für ...]]></description>
			<content:encoded><![CDATA[<p>Es ist möglich in einer WPF Applikation das Icon dynamisch festzulegen. Das hat den Hintergrund, dass z.B. wenn die Applikation gerade eine Aufgabe erledigt, so der Anwender über das Icon auf den Status aufmerksam gemacht wird (blur, SandUhr o.ä.). Das selbe gilt natürlich für <span style="text-decoration: underline;">alle</span> Bilder die man in der Applikation verwendet.</p>
<p>Man geht hier wie folgt vor:</p>
<p>Ein Image hinzufügen über Rechtsklick, Hinzufügen, Vorhandenes Element in den jeweiligen Projektordner.</p>
<p><a href="http://www.biggle.de/blog/wp-content/uploads/2010/01/Icon.jpg"><img class="alignnone size-full wp-image-3591" title="Icon" src="http://www.biggle.de/blog/wp-content/uploads/2010/01/Icon.jpg" alt="" width="457" height="432" /></a></p>
<p>In den Eigenschaften des Bildes (F4) den &#8220;Buildvorgang&#8221; auf &#8220;Resource&#8221; setzen und bei &#8220;In Ausgabeverzeichnis kopieren&#8221; auf  &#8220;Immer kopieren&#8221; setzen.</p>
<p><a href="http://www.biggle.de/blog/wp-content/uploads/2010/01/icon2.jpg"><img class="alignnone size-full wp-image-3592" title="icon2" src="http://www.biggle.de/blog/wp-content/uploads/2010/01/icon2.jpg" alt="" width="333" height="167" /></a></p>
<p>Im jeweiligen Style die ImageSource definieren, hierbei den relativen Pfad von der Style.xaml zum Bild beachten:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>ImageSource x<span style="color: #339933;">:</span><span style="color: #990000;">Key</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;ApplicationIcon&quot;</span><span style="color: #339933;">&gt;</span>images<span style="color: #339933;">/</span>logo<span style="color: #339933;">.</span>png<span style="color: #339933;">&lt;/</span>ImageSource<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Und in der Windows.xaml (unter CAL in der Shell.xaml) das Icon festlegen:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">Icon<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{DynamicResource ApplicationIcon}&quot;</span></pre></div></div>

<p>Hier darauf achten, DynamicResource anstelle von StaticResource, da es sonst während der Laufzeit nicht möglich ist, diese Resource zu wechseln.</p>
<p><br class="spacer_" /></p>
<p>Viel Spass beim entwickeln : )</p>
<hr /><p style="float:right; font-size:0.9em;">Dieser Beitrag stammt von <a href="http://www.biggle.de">Mario Priebe</a>.</p><h2  class="related_post_title">Ähnliche Beiträge</h2><ul class="related_post"><li>25. November 2009 -- <a href="http://www.biggle.de/blog/mulitline-textbox-xaml-quicky" title="Multiline TextBox &#8211; XAML Quicky">Multiline TextBox &#8211; XAML Quicky</a></li><li>25. Juli 2009 -- <a href="http://www.biggle.de/blog/textbox-mit-schatten-xaml-quicky" title="TextBox mit Schatten &#8211; XAML Quicky">TextBox mit Schatten &#8211; XAML Quicky</a></li><li>18. Juni 2009 -- <a href="http://www.biggle.de/blog/emailvalidationconverter-wpf-quicky" title="EMailValidationConverter &#8211; WPF Quicky">EMailValidationConverter &#8211; WPF Quicky</a></li><li>18. Juni 2009 -- <a href="http://www.biggle.de/blog/birthdayconverter-wpf-quicky" title="BirthdayConverter &#8211; WPF Quicky">BirthdayConverter &#8211; WPF Quicky</a></li><li>26. Februar 2009 -- <a href="http://www.biggle.de/blog/contextmenu-wpf-xaml-quicky" title="contextmenu &#8211; WPF / XAML Quicky">contextmenu &#8211; WPF / XAML Quicky</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.biggle.de/blog/dynamisches-applikations-icon-xaml/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
