<?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; WPF</title>
	<atom:link href="http://www.biggle.de/blog/category/development/wpf/feed" rel="self" type="application/rss+xml" />
	<link>http://www.biggle.de/blog</link>
	<description>Web- und Software Development</description>
	<lastBuildDate>Tue, 07 Feb 2012 13:08:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Asynchrones Bef&#252;llen einer ObservableCollection&lt;T&gt; in einem ViewModel</title>
		<link>http://www.biggle.de/blog/asynchrones-befllen-einer-observablecollectiont-in-einem-viewmodel</link>
		<comments>http://www.biggle.de/blog/asynchrones-befllen-einer-observablecollectiont-in-einem-viewmodel#comments</comments>
		<pubDate>Sat, 14 Jan 2012 17:46:21 +0000</pubDate>
		<dc:creator>Mario Priebe</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[async]]></category>
		<category><![CDATA[MVVM]]></category>

		<guid isPermaLink="false">http://www.biggle.de/blog/?p=6822</guid>
		<description><![CDATA[Die Aufgabenstellung beschreibt, das innerhalb eine ViewModels Daten aus einer Datenbank ausgelesen und über der Netzwerkverbindung noch weiter verarbeitet werden müssen. Hier liegt es auf der Hand, dass eine asynchrone Lösung her muss, sprich es muss unter allen Umständen verhindert werden, dass die UI blockiert. Wie man das machen kann, zeige ich wie folgt: Ich [...]]]></description>
			<content:encoded><![CDATA[<p>Die Aufgabenstellung beschreibt, das innerhalb eine ViewModels Daten aus einer Datenbank ausgelesen und über der Netzwerkverbindung noch weiter verarbeitet werden müssen. Hier liegt es auf der Hand, dass eine asynchrone Lösung her muss, sprich es muss unter allen Umständen verhindert werden, dass die UI blockiert.</p>
<p>Wie man das machen kann, zeige ich wie folgt:</p>
<p>Ich erstelle mir vorerst einen einfachen Delegate. </p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:e5b85b31-b029-423a-bb01-215ee0f008c5" class="wlWriterEditableSmartContent">
<pre style=" width: 500px; height: 50px;background-color:White;overflow: auto;">
<div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)

http://www.CodeHighlighter.com/

--><span style="color: #008080;">1</span> <span style="color: #0000FF;">private</span><span style="color: #000000;"> </span><span style="color: #0000FF;">delegate</span><span style="color: #000000;"> </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> AsyncAwsDelegate();</span></div>
</pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>Im Konstruktor der ViewModels, bzw in einem Command wird dann an diesem Delegate ein BeginInvoke aufgerufen, der die Methode zur asynchronen Verarbeitung zugewiesen bekommt.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:624b5591-6a79-4b1a-9cc6-d37511a29814" class="wlWriterEditableSmartContent">
<pre style=" width: 500px; height: 100px;background-color:White;overflow: auto;">
<div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)

http://www.CodeHighlighter.com/

--><span style="color: #008080;">1</span> <span style="color: #0000FF;">public</span><span style="color: #000000;"> MainViewModel()
</span><span style="color: #008080;">2</span> <span style="color: #000000;">{
</span><span style="color: #008080;">3</span> <span style="color: #000000;">    AsyncAwsDelegate del </span><span style="color: #000000;">=</span><span style="color: #000000;"> (FetchItemsAsync);
</span><span style="color: #008080;">4</span> <span style="color: #000000;">    del.BeginInvoke(</span><span style="color: #0000FF;">null</span><span style="color: #000000;">, </span><span style="color: #0000FF;">null</span><span style="color: #000000;">);
</span><span style="color: #008080;">5</span> <span style="color: #000000;">}</span></div>
</pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>In dieser Methode findet dann der Prozess statt, wo die Items verarbeitet und einer ObservableCollection&lt;T&gt; hinzugefügt werden.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:f5ee527a-8418-4b20-94b2-93417d89eae6" class="wlWriterEditableSmartContent">
<pre style=" width: 500px; height: 100px;background-color:White;overflow: auto;">
<div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)

http://www.CodeHighlighter.com/

--><span style="color: #008080;">1</span> <span style="color: #0000FF;">private</span><span style="color: #000000;"> </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> FetchItemsAsync()
</span><span style="color: #008080;">2</span> <span style="color: #000000;">{
</span><span style="color: #008080;">3</span> <span style="color: #000000;">    var items </span><span style="color: #000000;">=</span><span style="color: #000000;"> _dataLayer.Items.ToList();
</span><span style="color: #008080;">4</span> <span style="color: #000000;">    items.ForEach(i </span><span style="color: #000000;">=&gt;</span><span style="color: #000000;"> Items.Add(_aws.ItemLookup(i.ItemId)));
</span><span style="color: #008080;">5</span> <span style="color: #000000;">}</span></div>
</pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>Das geht leider nicht ohne Dispatcher, sprich wenn ich die “normale” ObservableCollection verwenden würde, müsste ich zuerst in den UI Thread gelangen, ansonsten knallt es.</p>
<p>Dazu konnte ich eine nette spezialisierte Klasse <a href="http://www.biggle.de/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3N0YWNrb3ZlcmZsb3cuY29tL2EvMzkwOTUyMy8xMTkxMDk=">finden</a>, die mir diese Arbeit abnimmt.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:ead36f24-b44b-43d7-b2b5-715eb7cc5a5a" class="wlWriterEditableSmartContent">
<pre style=" width: 500px; height: 250px;background-color:White;overflow: auto;">
<div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)

http://www.CodeHighlighter.com/

--><span style="color: #008080;"> 1</span> <span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">class</span><span style="color: #000000;"> DispatchingObservableCollection</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">T</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"> : ObservableCollection</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">T</span><span style="color: #000000;">&gt;</span><span style="color: #000000;">
</span><span style="color: #008080;"> 2</span> <span style="color: #000000;">{
</span><span style="color: #008080;"> 3</span> <span style="color: #000000;">    </span><span style="color: #0000FF;">private</span><span style="color: #000000;"> </span><span style="color: #0000FF;">readonly</span><span style="color: #000000;"> Dispatcher _currentDispatcher;
</span><span style="color: #008080;"> 4</span> <span style="color: #000000;">
</span><span style="color: #008080;"> 5</span> <span style="color: #000000;">    </span><span style="color: #808080;">///</span><span style="color: #008000;"> </span><span style="color: #808080;">&lt;summary&gt;</span><span style="color: #008000;">
</span><span style="color: #008080;"> 6</span> <span style="color: #008000;">    </span><span style="color: #808080;">///</span><span style="color: #008000;"> The default constructor of the ObservableCollection
</span><span style="color: #008080;"> 7</span> <span style="color: #008000;">    </span><span style="color: #808080;">///</span><span style="color: #008000;"> </span><span style="color: #808080;">&lt;/summary&gt;</span><span style="color: #808080;">
</span><span style="color: #008080;"> 8</span> <span style="color: #808080;"></span><span style="color: #000000;">    </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> DispatchingObservableCollection()
</span><span style="color: #008080;"> 9</span> <span style="color: #000000;">    {
</span><span style="color: #008080;">10</span> <span style="color: #000000;">        </span><span style="color: #008000;">//</span><span style="color: #008000;">Assign the current Dispatcher (owner of the collection)</span><span style="color: #008000;">
</span><span style="color: #008080;">11</span> <span style="color: #008000;"></span><span style="color: #000000;">        _currentDispatcher </span><span style="color: #000000;">=</span><span style="color: #000000;"> Dispatcher.CurrentDispatcher;
</span><span style="color: #008080;">12</span> <span style="color: #000000;">    }
</span><span style="color: #008080;">13</span> <span style="color: #000000;">
</span><span style="color: #008080;">14</span> <span style="color: #000000;">    </span><span style="color: #808080;">///</span><span style="color: #008000;"> </span><span style="color: #808080;">&lt;summary&gt;</span><span style="color: #008000;">
</span><span style="color: #008080;">15</span> <span style="color: #008000;">    </span><span style="color: #808080;">///</span><span style="color: #008000;"> Executes this action in the right thread
</span><span style="color: #008080;">16</span> <span style="color: #008000;">    </span><span style="color: #808080;">///</span><span style="color: #008000;"> </span><span style="color: #808080;">&lt;/summary&gt;</span><span style="color: #008000;">
</span><span style="color: #008080;">17</span> <span style="color: #008000;">    </span><span style="color: #808080;">///</span><span style="color: #808080;">&lt;param name=&quot;action&quot;&gt;</span><span style="color: #008000;">The action which should be executed</span><span style="color: #808080;">&lt;/param&gt;</span><span style="color: #808080;">
</span><span style="color: #008080;">18</span> <span style="color: #808080;"></span><span style="color: #000000;">    </span><span style="color: #0000FF;">private</span><span style="color: #000000;"> </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> DoDispatchedAction(Action action)
</span><span style="color: #008080;">19</span> <span style="color: #000000;">    {
</span><span style="color: #008080;">20</span> <span style="color: #000000;">        </span><span style="color: #0000FF;">if</span><span style="color: #000000;"> (_currentDispatcher.CheckAccess())
</span><span style="color: #008080;">21</span> <span style="color: #000000;">            action();
</span><span style="color: #008080;">22</span> <span style="color: #000000;">        </span><span style="color: #0000FF;">else</span><span style="color: #000000;">
</span><span style="color: #008080;">23</span> <span style="color: #000000;">            _currentDispatcher.Invoke(DispatcherPriority.DataBind, action);
</span><span style="color: #008080;">24</span> <span style="color: #000000;">    }
</span><span style="color: #008080;">25</span> <span style="color: #000000;">
</span><span style="color: #008080;">26</span> <span style="color: #000000;">    </span><span style="color: #808080;">///</span><span style="color: #008000;"> </span><span style="color: #808080;">&lt;summary&gt;</span><span style="color: #008000;">
</span><span style="color: #008080;">27</span> <span style="color: #008000;">    </span><span style="color: #808080;">///</span><span style="color: #008000;"> Clears all items
</span><span style="color: #008080;">28</span> <span style="color: #008000;">    </span><span style="color: #808080;">///</span><span style="color: #008000;"> </span><span style="color: #808080;">&lt;/summary&gt;</span><span style="color: #808080;">
</span><span style="color: #008080;">29</span> <span style="color: #808080;"></span><span style="color: #000000;">    </span><span style="color: #0000FF;">protected</span><span style="color: #000000;"> </span><span style="color: #0000FF;">override</span><span style="color: #000000;"> </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> ClearItems()
</span><span style="color: #008080;">30</span> <span style="color: #000000;">    {
</span><span style="color: #008080;">31</span> <span style="color: #000000;">        DoDispatchedAction(() </span><span style="color: #000000;">=&gt;</span><span style="color: #000000;"> </span><span style="color: #0000FF;">base</span><span style="color: #000000;">.ClearItems());
</span><span style="color: #008080;">32</span> <span style="color: #000000;">    }
</span><span style="color: #008080;">33</span> <span style="color: #000000;">
</span><span style="color: #008080;">34</span> <span style="color: #000000;">    </span><span style="color: #808080;">///</span><span style="color: #008000;"> </span><span style="color: #808080;">&lt;summary&gt;</span><span style="color: #008000;">
</span><span style="color: #008080;">35</span> <span style="color: #008000;">    </span><span style="color: #808080;">///</span><span style="color: #008000;"> Inserts a item at the specified index
</span><span style="color: #008080;">36</span> <span style="color: #008000;">    </span><span style="color: #808080;">///</span><span style="color: #008000;"> </span><span style="color: #808080;">&lt;/summary&gt;</span><span style="color: #008000;">
</span><span style="color: #008080;">37</span> <span style="color: #008000;">    </span><span style="color: #808080;">///</span><span style="color: #808080;">&lt;param name=&quot;index&quot;&gt;</span><span style="color: #008000;">The index where the item should be inserted</span><span style="color: #808080;">&lt;/param&gt;</span><span style="color: #008000;">
</span><span style="color: #008080;">38</span> <span style="color: #008000;">    </span><span style="color: #808080;">///</span><span style="color: #808080;">&lt;param name=&quot;item&quot;&gt;</span><span style="color: #008000;">The item which should be inserted</span><span style="color: #808080;">&lt;/param&gt;</span><span style="color: #808080;">
</span><span style="color: #008080;">39</span> <span style="color: #808080;"></span><span style="color: #000000;">    </span><span style="color: #0000FF;">protected</span><span style="color: #000000;"> </span><span style="color: #0000FF;">override</span><span style="color: #000000;"> </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> InsertItem(</span><span style="color: #0000FF;">int</span><span style="color: #000000;"> index, T item)
</span><span style="color: #008080;">40</span> <span style="color: #000000;">    {
</span><span style="color: #008080;">41</span> <span style="color: #000000;">        DoDispatchedAction(() </span><span style="color: #000000;">=&gt;</span><span style="color: #000000;"> </span><span style="color: #0000FF;">base</span><span style="color: #000000;">.InsertItem(index, item));
</span><span style="color: #008080;">42</span> <span style="color: #000000;">    }
</span><span style="color: #008080;">43</span> <span style="color: #000000;">}</span></div>
</pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>Da die ObservableCollection das INotifyPropertyChanged Interface implementiert, brauch ich auch nicht mehr dafür Sorge tragen, dass sich bei jedem Zufügen eines Items die UI aktualisieren muss.</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/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5iaWdnbGUuZGU=">Mario Priebe</a>.</p> <img src="http://www.biggle.de/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=6822" width="1" height="1" style="display: none;" /><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>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></ul>]]></content:encoded>
			<wfw:commentRss>http://www.biggle.de/blog/asynchrones-befllen-einer-observablecollectiont-in-einem-viewmodel/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>DataBindings debuggen &#8211; WPF</title>
		<link>http://www.biggle.de/blog/databindings-debuggen-wpf</link>
		<comments>http://www.biggle.de/blog/databindings-debuggen-wpf#comments</comments>
		<pubDate>Sun, 24 Jul 2011 12:21:33 +0000</pubDate>
		<dc:creator>Mario Priebe</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://www.biggle.de/blog/databindings-debuggen-wpf</guid>
		<description><![CDATA[Beim DataBinding ist es nicht immer einfach festzustellen, warum denn nun ein Wert nicht angezeigt wird. Die Fehlersuche zeigt sich mitunter, gerade auch in immer größer werdenden Projekten, als äußerst schwierig. Das liegt daran, das im DataBinding keine Exception geworfen werden, wenn hier ein Element, eine Property, oder ein Path nicht gefunden wird. Ein paar [...]]]></description>
			<content:encoded><![CDATA[<p>Beim <strong>DataBinding</strong> ist es nicht immer einfach festzustellen, warum denn nun ein Wert nicht angezeigt wird. Die Fehlersuche zeigt sich mitunter, gerade auch in immer größer werdenden Projekten, als äußerst schwierig. </p>
<p>Das liegt daran, das im DataBinding keine Exception geworfen werden, wenn hier ein Element, eine Property, oder ein Path nicht gefunden wird.</p>
<p>Ein paar kleine Tricks können Abhilfe und für ein stressfreies Wochenende sorgen.</p>
<h2>Tipp 1: Ausgabefenster</h2>
<p>Lässt man sich beim <strong>Debuggen</strong> das Ausgabefenster von Visual Studio anzeigen, kann man diesem schon wertvolle Informationen entlocken.</p>
<p>Eine Fehlermeldung könnte z.B. wie folgt aussehen:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:c084c814-cc53-47d3-93a6-a8625a21d9ef" class="wlWriterEditableSmartContent">
<pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; white-space: pre-wrap; word-wrap: break-word;overflow: auto;"><span style="color: #000000;">System.Windows.Data Error: </span><span style="color: #800080;">40</span><span style="color: #000000;"> : BindingExpression path error: </span><span style="color: #800000;">'</span><span style="color: #800000;">Mesage</span><span style="color: #800000;">'</span><span style="color: #000000;"> property not found on </span><span style="color: #800000;">'</span><span style="color: #800000;">object</span><span style="color: #800000;">'</span><span style="color: #000000;"> </span><span style="color: #800000;">''</span><span style="color: #000000;">MainWindow</span><span style="color: #800000;">'</span><span style="color: #800000;"> (Name=</span><span style="color: #800000;">''</span><span style="color: #800000;">)</span><span style="color: #800000;">'</span><span style="color: #000000;">. BindingExpression:Path</span><span style="color: #000000;">=</span><span style="color: #000000;">Mesage; DataItem</span><span style="color: #000000;">=</span><span style="color: #800000;">'</span><span style="color: #800000;">MainWindow</span><span style="color: #800000;">'</span><span style="color: #000000;"> (Name</span><span style="color: #000000;">=</span><span style="color: #800000;">''</span><span style="color: #000000;">); target element </span><span style="color: #0000FF;">is</span><span style="color: #000000;"> </span><span style="color: #800000;">'</span><span style="color: #800000;">TextBox</span><span style="color: #800000;">'</span><span style="color: #000000;"> (Name</span><span style="color: #000000;">=</span><span style="color: #800000;">''</span><span style="color: #000000;">); target property </span><span style="color: #0000FF;">is</span><span style="color: #000000;"> </span><span style="color: #800000;">'</span><span style="color: #800000;">Text</span><span style="color: #800000;">'</span><span style="color: #000000;"> (type </span><span style="color: #800000;">'</span><span style="color: #800000;">String</span><span style="color: #800000;">'</span><span style="color: #000000;">)</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>Hier finde ich dann, das ich mich bei der Property “Message” verschrieben habe (“Mesage”).</p>
<p>Um das Ausgabefenster anzuzeigen, geht man unter <strong>Ansicht</strong> &gt; <strong>Ausgabe</strong> oder zeigt dieses über die Tastenkombination <strong>CTRL+W+O</strong> an. Man muss hier aber darauf achten, dass man sich bereits im Debugging befindet.</p>
<p>Vorher sollte man überprüfen ob die Einstellungen in Visual Studio richtig sind.</p>
<p>Dazu geht man nach <strong>Extras &gt; Optionen &gt; Debugging &gt; Ausgabefenster</strong> und wählt hier unter WPF-Ablaufverfolgung im DropDown “<strong>DataBinding</strong>” die Option “<strong>Alle</strong>”</p>
<p><a href="http://www.biggle.de/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5iaWdnbGUuZGUvYmxvZy93cC1jb250ZW50L3VwbG9hZHMvMjAxMS8wNy9pbWFnZTMucG5n"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.biggle.de/blog/wp-content/uploads/2011/07/image_thumb3.png" width="504" height="314" /></a></p>
<p>&#160;</p>
<h2>Tipp 2: PresentationTraceSources</h2>
<p>Wem die Informationen in der Ausgabe nicht ausreichen, kann sein Control um weitere, ausführlichere Informationen erweitern. </p>
<p>Hierzu referenziert man auf den Namespace <strong>System.Diagnostics</strong> aus der Assembly <strong>WindowsBase</strong></p>
<p><a href="http://www.biggle.de/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5iaWdnbGUuZGUvYmxvZy93cC1jb250ZW50L3VwbG9hZHMvMjAxMS8wNy9pbWFnZTQucG5n"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.biggle.de/blog/wp-content/uploads/2011/07/image_thumb4.png" width="504" height="231" /></a></p>
<p>&#160;</p>
<p>Anschließend erweitert man sein Binding um das <strong>AttachedProperty</strong> <strong>TraceLevel</strong> aus der Klasse <strong>PresentationTraceSources</strong> und dieses um den Wert <strong>High</strong>:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:e54f6dab-ef3c-4c15-bf73-30c5b66214ad" class="wlWriterEditableSmartContent">
<pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; white-space: pre-wrap; word-wrap: break-word;overflow: auto;"><span style="color: #000000;">&lt;</span><span style="color: #000000;">TextBox Text</span><span style="color: #000000;">=</span><span style="color: #800000;">"</span><span style="color: #800000;">{Binding Mesage, debugging:PresentationTraceSources.TraceLevel=High}</span><span style="color: #800000;">"</span><span style="color: #000000;">  </span><span style="color: #000000;">/&gt;</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>Hier bekommt man dann richtig viele Informationen zu einem Binding, die ich hier auszugsweise nur als Grafik zeigen möchte:</p>
<p><a href="http://www.biggle.de/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5iaWdnbGUuZGUvYmxvZy93cC1jb250ZW50L3VwbG9hZHMvMjAxMS8wNy9pbWFnZTUucG5n"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.biggle.de/blog/wp-content/uploads/2011/07/image_thumb5.png" width="504" height="223" /></a></p>
<p>Mögliche Werte in TraceLevel können sein: High, Low, Medium und None.</p>
<h2>Tipp 3: IValueConverter</h2>
<p>Nun, es kommt vor, dass obwohl die Properties richtig definiert sind, immer noch nicht das angezeigt wird, was man eigentlich erwartet. Hier kommt die dritte Möglichkeit ins Spiel. </p>
<p>Es wäre doch toll, wenn man irgendwie einen BreakPoint irgendwo setzen könnte um nach gewohnter Manier zu debuggen. Ja, auch das ist möglich.</p>
<p>Hierzu definiert man sich einen Converter, der lediglich den Value durchreicht:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:454b9518-2ad8-497e-b1b1-bdaa58de3778" class="wlWriterEditableSmartContent">
<pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; white-space: pre-wrap; word-wrap: break-word;overflow: auto;"><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">class</span><span style="color: #000000;"> DebuggingConverter : IValueConverter
{
    </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">object</span><span style="color: #000000;"> Convert(</span><span style="color: #0000FF;">object</span><span style="color: #000000;"> value, Type targetType, </span><span style="color: #0000FF;">object</span><span style="color: #000000;"> parameter, System.Globalization.CultureInfo culture)
    {
        </span><span style="color: #0000FF;">return</span><span style="color: #000000;"> value;
    }

    </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">object</span><span style="color: #000000;"> ConvertBack(</span><span style="color: #0000FF;">object</span><span style="color: #000000;"> value, Type targetType, </span><span style="color: #0000FF;">object</span><span style="color: #000000;"> parameter, System.Globalization.CultureInfo culture)
    {
        </span><span style="color: #0000FF;">return</span><span style="color: #000000;"> value;
    }
}</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>Nun referenziert man den Namespace zum Converter und in den Resources des Elements wird der Converter bekannt gemacht:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:e5247a9f-1d97-49e0-95b6-90180f4a4474" class="wlWriterEditableSmartContent">
<pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; white-space: pre-wrap; word-wrap: break-word;overflow: auto;"><span style="color: #000000;">xmlns:converter</span><span style="color: #000000;">=</span><span style="color: #800000;">"</span><span style="color: #800000;">clr-namespace:Debugging</span><span style="color: #800000;">"</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:923db1d9-42f4-484e-b28b-a32e1f2cc344" class="wlWriterEditableSmartContent">
<pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; white-space: pre-wrap; word-wrap: break-word;overflow: auto;"><span style="color: #000000;">&lt;</span><span style="color: #000000;">Grid.Resources</span><span style="color: #000000;">&gt;</span><span style="color: #000000;">
    </span><span style="color: #000000;">&lt;</span><span style="color: #000000;">converter:DebuggingConverter x:Key</span><span style="color: #000000;">=</span><span style="color: #800000;">"</span><span style="color: #800000;">debugger</span><span style="color: #800000;">"</span><span style="color: #000000;"> </span><span style="color: #000000;">/&gt;</span><span style="color: #000000;">
</span><span style="color: #000000;">&lt;/</span><span style="color: #000000;">Grid.Resources</span><span style="color: #000000;">&gt;</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>Im Binding wird der Converter dann noch definiert</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:f63758ae-a5d8-4cc1-9142-c0a85ba24537" class="wlWriterEditableSmartContent">
<pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; white-space: pre-wrap; word-wrap: break-word;overflow: auto;"><span style="color: #000000;">&lt;</span><span style="color: #000000;">TextBox Text</span><span style="color: #000000;">=</span><span style="color: #800000;">"</span><span style="color: #800000;">{Binding Message, Converter={StaticResource debugger}}</span><span style="color: #800000;">"</span><span style="color: #000000;">  </span><span style="color: #000000;">/&gt;</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>Jetzt setze ich meine BreakPoints im <strong>Convert</strong> oder beim TwoWay-Binding auch im <strong>ConvertBack</strong> und kann mir den Wert genauer anschauen.</p>
<p>&#160;</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/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5iaWdnbGUuZGU=">Mario Priebe</a>.</p> <img src="http://www.biggle.de/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=6572" width="1" height="1" style="display: none;" /><h2  class="related_post_title">Ähnliche Beiträge</h2><ul class="related_post"><li>23. Juli 2011 -- <a href="http://www.biggle.de/blog/gemeinsamen-validation-style-fr-controls-wpf" title="Gemeinsamen Validation Style f&uuml;r Controls &#8211; WPF">Gemeinsamen Validation Style f&uuml;r Controls &#8211; WPF</a></li><li>25. Juni 2011 -- <a href="http://www.biggle.de/blog/enumeration-in-einer-combobox-darstellen-wpf-quicky" title="Enumeration in einer ComboBox darstellen &#8211; WPF Quicky">Enumeration in einer ComboBox darstellen &#8211; WPF Quicky</a></li><li>15. März 2011 -- <a href="http://www.biggle.de/blog/cookies-in-einer-wpf-applikation" title="Cookies in einer WPF Applikation">Cookies in einer WPF Applikation</a></li><li>6. März 2011 -- <a href="http://www.biggle.de/blog/multibinding-die-zweite" title="MultiBinding die Zweite">MultiBinding die Zweite</a></li><li>14. Februar 2011 -- <a href="http://www.biggle.de/blog/doppelklick-im-datagrid-abfangen-wpf-quicky" title="Doppelklick im DataGrid abfangen &#8211; WPF Quicky">Doppelklick im DataGrid abfangen &#8211; WPF Quicky</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.biggle.de/blog/databindings-debuggen-wpf/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Gemeinsamen Validation Style f&#252;r Controls &#8211; WPF</title>
		<link>http://www.biggle.de/blog/gemeinsamen-validation-style-fr-controls-wpf</link>
		<comments>http://www.biggle.de/blog/gemeinsamen-validation-style-fr-controls-wpf#comments</comments>
		<pubDate>Sat, 23 Jul 2011 13:42:35 +0000</pubDate>
		<dc:creator>Mario Priebe</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://www.biggle.de/blog/gemeinsamen-validation-style-fr-controls-wpf</guid>
		<description><![CDATA[Um einen gemeinsamen Style für Validierungsfehler in der WPF zu verwenden, definiert man einen Style für den TargetType Control und vergibt diesen einen Key. &#60;Style x:Key="validationTriggerBase" TargetType="Control"&#62; &#60;Style.Triggers&#62; &#60;Trigger Property="Validation.HasError" Value="true"&#62; &#60;Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent }" /&#62; &#60;/Trigger&#62; &#60;/Style.Triggers&#62; &#60;/Style&#62; &#60;Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource validationTriggerBase}" /&#62; Viel Spaß beim entwickeln : ) Dieser [...]]]></description>
			<content:encoded><![CDATA[<p>Um einen gemeinsamen Style für Validierungsfehler in der WPF zu verwenden, definiert man einen Style für den TargetType Control und vergibt diesen einen Key.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:8dec15c3-d4b0-4687-93b7-c579bbcda6d8" class="wlWriterEditableSmartContent">
<pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; white-space: pre-wrap; word-wrap: break-word;overflow: auto;"><span style="color: #000000;">&lt;</span><span style="color: #000000;">Style x:Key</span><span style="color: #000000;">=</span><span style="color: #800000;">"</span><span style="color: #800000;">validationTriggerBase</span><span style="color: #800000;">"</span><span style="color: #000000;"> TargetType</span><span style="color: #000000;">=</span><span style="color: #800000;">"</span><span style="color: #800000;">Control</span><span style="color: #800000;">"</span><span style="color: #000000;">&gt;</span><span style="color: #000000;">
    </span><span style="color: #000000;">&lt;</span><span style="color: #000000;">Style.Triggers</span><span style="color: #000000;">&gt;</span><span style="color: #000000;">
        </span><span style="color: #000000;">&lt;</span><span style="color: #000000;">Trigger Property</span><span style="color: #000000;">=</span><span style="color: #800000;">"</span><span style="color: #800000;">Validation.HasError</span><span style="color: #800000;">"</span><span style="color: #000000;"> Value</span><span style="color: #000000;">=</span><span style="color: #800000;">"</span><span style="color: #800000;">true</span><span style="color: #800000;">"</span><span style="color: #000000;">&gt;</span><span style="color: #000000;">
            </span><span style="color: #000000;">&lt;</span><span style="color: #000000;">Setter Property</span><span style="color: #000000;">=</span><span style="color: #800000;">"</span><span style="color: #800000;">ToolTip</span><span style="color: #800000;">"</span><span style="color: #000000;"> Value</span><span style="color: #000000;">=</span><span style="color: #800000;">"</span><span style="color: #800000;">{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent   }</span><span style="color: #800000;">"</span><span style="color: #000000;"> </span><span style="color: #000000;">/&gt;</span><span style="color: #000000;">
        </span><span style="color: #000000;">&lt;/</span><span style="color: #000000;">Trigger</span><span style="color: #000000;">&gt;</span><span style="color: #000000;">
    </span><span style="color: #000000;">&lt;/</span><span style="color: #000000;">Style.Triggers</span><span style="color: #000000;">&gt;</span><span style="color: #000000;">
</span><span style="color: #000000;">&lt;/</span><span style="color: #000000;">Style</span><span style="color: #000000;">&gt;</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>Im Anschluss, kann man einzelne Controls diesen Style zuweisen:</p>
<p><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:e0d41a29-4e6f-4969-af3e-0a2e19c0c20d" class="wlWriterEditableSmartContent">
<pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; white-space: pre-wrap; word-wrap: break-word;overflow: auto;"><span style="color: #000000;">&lt;</span><span style="color: #000000;">Style TargetType</span><span style="color: #000000;">=</span><span style="color: #800000;">"</span><span style="color: #800000;">{x:Type DatePicker}</span><span style="color: #800000;">"</span><span style="color: #000000;"> BasedOn</span><span style="color: #000000;">=</span><span style="color: #800000;">"</span><span style="color: #800000;">{StaticResource validationTriggerBase}</span><span style="color: #800000;">"</span><span style="color: #000000;"> </span><span style="color: #000000;">/&gt;</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
</p>
<p><a href="http://www.biggle.de/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5iaWdnbGUuZGUvYmxvZy93cC1jb250ZW50L3VwbG9hZHMvMjAxMS8wNy9pbWFnZTEucG5n"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.biggle.de/blog/wp-content/uploads/2011/07/image_thumb1.png" width="244" height="75" /></a></p>
<p><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:c0e96b0f-9269-4518-9d0a-95de41e07d1b" class="wlWriterEditableSmartContent">
<pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; white-space: pre-wrap; word-wrap: break-word;overflow: auto;"><span style="color: #000000;">&lt;</span><span style="color: #000000;">Style TargetType</span><span style="color: #000000;">=</span><span style="color: #800000;">"</span><span style="color: #800000;">{x:Type TextBox}</span><span style="color: #800000;">"</span><span style="color: #000000;"> BasedOn</span><span style="color: #000000;">=</span><span style="color: #800000;">"</span><span style="color: #800000;">{StaticResource validationTriggerBase}</span><span style="color: #800000;">"</span><span style="color: #000000;"> </span><span style="color: #000000;">/&gt;</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
</p>
<p><a href="http://www.biggle.de/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5iaWdnbGUuZGUvYmxvZy93cC1jb250ZW50L3VwbG9hZHMvMjAxMS8wNy9pbWFnZTIucG5n"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.biggle.de/blog/wp-content/uploads/2011/07/image_thumb2.png" width="244" height="58" /></a></p>
<p>Nicht vergessen, das bindende Control muss <em>ValidatesOnDataErrors=True</em> aufrufen.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:d6065793-78f1-4a3e-b89c-4ce4ef0e1eac" class="wlWriterEditableSmartContent">
<pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; white-space: pre-wrap; word-wrap: break-word;overflow: auto;"><span style="color: #000000;">&lt;</span><span style="color: #000000;">StackPanel Width</span><span style="color: #000000;">=</span><span style="color: #800000;">"</span><span style="color: #800000;">250</span><span style="color: #800000;">"</span><span style="color: #000000;"> HorizontalAlignment</span><span style="color: #000000;">=</span><span style="color: #800000;">"</span><span style="color: #800000;">Center</span><span style="color: #800000;">"</span><span style="color: #000000;"> DataContext</span><span style="color: #000000;">=</span><span style="color: #800000;">"</span><span style="color: #800000;">{StaticResource Person}</span><span style="color: #800000;">"</span><span style="color: #000000;">&gt;</span><span style="color: #000000;">
    </span><span style="color: #000000;">&lt;</span><span style="color: #000000;">TextBox Text</span><span style="color: #000000;">=</span><span style="color: #800000;">"</span><span style="color: #800000;">{Binding Name, ValidatesOnDataErrors=True, </span><span style="color: #800000;">
</span><span style="color: #000000;">        UpdateSourceTrigger</span><span style="color: #000000;">=</span><span style="color: #000000;">PropertyChanged}</span><span style="color: #800000;">"</span><span style="color: #800000;"> /&gt;</span><span style="color: #800000;">
</span><span style="color: #000000;">
    </span><span style="color: #000000;">&lt;</span><span style="color: #000000;">DatePicker SelectedDate</span><span style="color: #000000;">=</span><span style="color: #800000;">"</span><span style="color: #800000;">{Binding Birthday, StringFormat=dd.mm.yyyy, </span><span style="color: #800000;">
</span><span style="color: #000000;">        ValidatesOnDataErrors</span><span style="color: #000000;">=</span><span style="color: #000000;">True,
        UpdateSourceTrigger</span><span style="color: #000000;">=</span><span style="color: #000000;">PropertyChanged, Converter</span><span style="color: #000000;">=</span><span style="color: #000000;">{StaticResource conv}}</span><span style="color: #800000;">"</span><span style="color: #800000;"> /&gt;</span><span style="color: #800000;">
</span><span style="color: #000000;">&lt;/</span><span style="color: #000000;">StackPanel</span><span style="color: #000000;">&gt;</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<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/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5iaWdnbGUuZGU=">Mario Priebe</a>.</p> <img src="http://www.biggle.de/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=6565" width="1" height="1" style="display: none;" /><h2  class="related_post_title">Ähnliche Beiträge</h2><ul class="related_post"><li>24. Juli 2011 -- <a href="http://www.biggle.de/blog/databindings-debuggen-wpf" title="DataBindings debuggen &#8211; WPF">DataBindings debuggen &#8211; WPF</a></li><li>25. Juni 2011 -- <a href="http://www.biggle.de/blog/enumeration-in-einer-combobox-darstellen-wpf-quicky" title="Enumeration in einer ComboBox darstellen &#8211; WPF Quicky">Enumeration in einer ComboBox darstellen &#8211; WPF Quicky</a></li><li>15. März 2011 -- <a href="http://www.biggle.de/blog/cookies-in-einer-wpf-applikation" title="Cookies in einer WPF Applikation">Cookies in einer WPF Applikation</a></li><li>6. März 2011 -- <a href="http://www.biggle.de/blog/multibinding-die-zweite" title="MultiBinding die Zweite">MultiBinding die Zweite</a></li><li>14. Februar 2011 -- <a href="http://www.biggle.de/blog/doppelklick-im-datagrid-abfangen-wpf-quicky" title="Doppelklick im DataGrid abfangen &#8211; WPF Quicky">Doppelklick im DataGrid abfangen &#8211; WPF Quicky</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.biggle.de/blog/gemeinsamen-validation-style-fr-controls-wpf/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Enumeration in einer ComboBox darstellen &#8211; WPF Quicky</title>
		<link>http://www.biggle.de/blog/enumeration-in-einer-combobox-darstellen-wpf-quicky</link>
		<comments>http://www.biggle.de/blog/enumeration-in-einer-combobox-darstellen-wpf-quicky#comments</comments>
		<pubDate>Sat, 25 Jun 2011 05:24:43 +0000</pubDate>
		<dc:creator>Mario Priebe</dc:creator>
				<category><![CDATA[WPF]]></category>
		<category><![CDATA[Tipps]]></category>

		<guid isPermaLink="false">http://www.biggle.de/blog/enumeration-in-einer-combobox-darstellen-wpf-quicky</guid>
		<description><![CDATA[Um eine Aufzählung unter WPF in einer ComboBox darzustellen, brauch man nicht wirklich viel. Mit der Methode GetValues() aus der Klasse Enum, bekommt man einen Array mit den Konstanten aus der Aufzählung zurück. &#60;ComboBox ItemsSource="{Binding AutoCompleteFilters}" SelectedItem="{Binding SelectedFilterMode}" /&#62; Viel Spaß beim entwickeln : ) Dieser Beitrag stammt von Mario Priebe. Ähnliche Beiträge31. Juli 2011 [...]]]></description>
			<content:encoded><![CDATA[<p>Um eine Aufzählung unter WPF in einer ComboBox darzustellen, brauch man nicht wirklich viel. </p>
<p>Mit der Methode <strong>GetValues</strong>() aus der Klasse <strong><a href="http://www.biggle.de/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL21zZG4ubWljcm9zb2Z0LmNvbS9lbi11cy9saWJyYXJ5L3N5c3RlbS5lbnVtLmFzcHg=" target=\"_blank\">Enum</a></strong>, bekommt man einen Array mit den Konstanten aus der Aufzählung zurück.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:87f9b72d-3f3b-4a6a-8fb3-996d70438064" class="wlWriterEditableSmartContent">
<pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; white-space: pre-wrap; word-wrap: break-word;overflow: auto;"><span style="color: #000000;">&lt;</span><span style="color: #000000;">ComboBox ItemsSource</span><span style="color: #000000;">=</span><span style="color: #800000;">"</span><span style="color: #800000;">{Binding AutoCompleteFilters}</span><span style="color: #800000;">"</span><span style="color: #000000;"> SelectedItem</span><span style="color: #000000;">=</span><span style="color: #800000;">"</span><span style="color: #800000;">{Binding SelectedFilterMode}</span><span style="color: #800000;">"</span><span style="color: #000000;"> </span><span style="color: #000000;">/&gt;</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:03122e71-7e5a-469e-883a-3bdaed189929" class="wlWriterEditableSmartContent">
<pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; white-space: pre-wrap; word-wrap: break-word;overflow: auto;"><span style="color: #0000FF;">public</span><span style="color: #000000;"> List</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">AutoCompleteFilterMode</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"> AutoCompleteFilters { </span><span style="color: #0000FF;">get</span><span style="color: #000000;">; </span><span style="color: #0000FF;">set</span><span style="color: #000000;">; }

</span><span style="color: #0000FF;">private</span><span style="color: #000000;"> </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> SetAutoCompleteFilters()
{
    Array values </span><span style="color: #000000;">=</span><span style="color: #000000;"> Enum.GetValues((</span><span style="color: #0000FF;">typeof</span><span style="color: #000000;">(AutoCompleteFilterMode)));

    AutoCompleteFilters </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">new</span><span style="color: #000000;"> List</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">AutoCompleteFilterMode</span><span style="color: #000000;">&gt;</span><span style="color: #000000;">();
    </span><span style="color: #0000FF;">foreach</span><span style="color: #000000;"> (AutoCompleteFilterMode value </span><span style="color: #0000FF;">in</span><span style="color: #000000;"> values)
    {
        AutoCompleteFilters.Add(value);
    }
}</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p><a href="http://www.biggle.de/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5iaWdnbGUuZGUvYmxvZy93cC1jb250ZW50L3VwbG9hZHMvMjAxMS8wNi9pbWFnZS5wbmc="><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.biggle.de/blog/wp-content/uploads/2011/06/image_thumb.png" width="360" height="330" /></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/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5iaWdnbGUuZGU=">Mario Priebe</a>.</p> <img src="http://www.biggle.de/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=6503" width="1" height="1" style="display: none;" /><h2  class="related_post_title">Ähnliche Beiträge</h2><ul class="related_post"><li>31. Juli 2011 -- <a href="http://www.biggle.de/blog/gottmodus-in-windows-7-aktivieren" title="Gottmodus in Windows 7 aktivieren">Gottmodus in Windows 7 aktivieren</a></li><li>24. Juli 2011 -- <a href="http://www.biggle.de/blog/databindings-debuggen-wpf" title="DataBindings debuggen &#8211; WPF">DataBindings debuggen &#8211; WPF</a></li><li>23. Juli 2011 -- <a href="http://www.biggle.de/blog/gemeinsamen-validation-style-fr-controls-wpf" title="Gemeinsamen Validation Style f&uuml;r Controls &#8211; WPF">Gemeinsamen Validation Style f&uuml;r Controls &#8211; WPF</a></li><li>4. Juli 2011 -- <a href="http://www.biggle.de/blog/neuer-ordner-im-projekt-per-hotkey" title="Neuer Ordner im Projekt per Hotkey">Neuer Ordner im Projekt per Hotkey</a></li><li>15. März 2011 -- <a href="http://www.biggle.de/blog/cookies-in-einer-wpf-applikation" title="Cookies in einer WPF Applikation">Cookies in einer WPF Applikation</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.biggle.de/blog/enumeration-in-einer-combobox-darstellen-wpf-quicky/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cookies in einer WPF Applikation</title>
		<link>http://www.biggle.de/blog/cookies-in-einer-wpf-applikation</link>
		<comments>http://www.biggle.de/blog/cookies-in-einer-wpf-applikation#comments</comments>
		<pubDate>Tue, 15 Mar 2011 14:57:49 +0000</pubDate>
		<dc:creator>Mario Priebe</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://www.biggle.de/blog/?p=6306</guid>
		<description><![CDATA[Möchte man beispielsweise Authentifikationsinformationen während einer WPF-Client-Sitzung speichern, kann man hier an der Klasse Application die Methoden SetCookie und GetCookie verwenden. Folgendes einfaches Beispiel zeigt wie die Cookieinformationen abgelegt und gelesen werden können: XAML 1 2 3 4 5 6 7 8 9 &#60;StackPanel&#62; &#60;TextBox Name=&#34;tbUserName&#34; /&#62; &#60;TextBox Name=&#34;tbPassword&#34; /&#62; &#60;Button Content=&#34;SetCookie&#34; Click=&#34;Button_Click&#34; /&#62; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>Möchte man beispielsweise Authentifikationsinformationen während einer WPF-Client-Sitzung speichern, kann man hier an der Klasse Application die Methoden <a href="http://www.biggle.de/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL21zZG4ubWljcm9zb2Z0LmNvbS9lbi11cy9saWJyYXJ5L3N5c3RlbS53aW5kb3dzLmFwcGxpY2F0aW9uLnNldGNvb2tpZS5hc3B4">SetCookie</a> und <a href="http://www.biggle.de/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL21zZG4ubWljcm9zb2Z0LmNvbS9lbi11cy9saWJyYXJ5L3N5c3RlbS53aW5kb3dzLmFwcGxpY2F0aW9uLmdldGNvb2tpZS5hc3B4">GetCookie</a> verwenden.</p>
<p>Folgendes einfaches Beispiel zeigt wie die Cookieinformationen abgelegt und gelesen werden können:</p>
<p>XAML</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</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>TextBox Name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;tbUserName&quot;</span> <span style="color: #339933;">/&gt;</span>
    <span style="color: #339933;">&lt;</span>TextBox Name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;tbPassword&quot;</span> <span style="color: #339933;">/&gt;</span>        
    <span style="color: #339933;">&lt;</span>Button Content<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;SetCookie&quot;</span> Click<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Button_Click&quot;</span> <span style="color: #339933;">/&gt;</span>   
&nbsp;
    <span style="color: #339933;">&lt;</span>Button Content<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;GetCookie&quot;</span> Click<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Button_Click_1&quot;</span> <span style="color: #339933;">/&gt;</span> 
    <span style="color: #339933;">&lt;</span>TextBlock Name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;tbGetUserName&quot;</span> <span style="color: #339933;">/&gt;</span>        
    <span style="color: #339933;">&lt;</span>TextBlock Name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;tbGetPassword&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>C#</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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
</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> MainWindow <span style="color: #339933;">:</span> Window
<span style="color: #009900;">&#123;</span>
    Uri cookiePath <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Uri<span style="color: #009900;">&#40;</span><span style="color: #990000;">System</span><span style="color: #339933;">.</span>Environment<span style="color: #339933;">.</span>GetEnvironmentVariable<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;tmp&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> MainWindow<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>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> void Button_Click<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>
        <span style="color: #990000;">SetCookie</span><span style="color: #009900;">&#40;</span>cookiePath<span style="color: #339933;">,</span> tbUserName<span style="color: #339933;">.</span>Text<span style="color: #339933;">,</span> tbPassword<span style="color: #339933;">.</span>Text<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> void Button_Click_1<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>
        string c <span style="color: #339933;">=</span> GetCookie<span style="color: #009900;">&#40;</span>cookiePath<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>String<span style="color: #339933;">.</span>IsNullOrEmpty<span style="color: #009900;">&#40;</span>c<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">var</span> auth <span style="color: #339933;">=</span> GetAuthentification<span style="color: #009900;">&#40;</span>c<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            tbGetUserName<span style="color: #339933;">.</span>Text <span style="color: #339933;">=</span> auth<span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;Username&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
            tbGetPassword<span style="color: #339933;">.</span>Text <span style="color: #339933;">=</span> auth<span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;Password&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> static void <span style="color: #990000;">SetCookie</span><span style="color: #009900;">&#40;</span>Uri uri<span style="color: #339933;">,</span> String name<span style="color: #339933;">,</span> String value<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        String cookie <span style="color: #339933;">=</span> String<span style="color: #339933;">.</span>Format<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Username={0}Password={1}&quot;</span><span style="color: #339933;">,</span> name<span style="color: #339933;">,</span> value<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        Application<span style="color: #339933;">.</span><span style="color: #990000;">SetCookie</span><span style="color: #009900;">&#40;</span>uri<span style="color: #339933;">,</span> cookie<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> static String GetCookie<span style="color: #009900;">&#40;</span>Uri uri<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        string c <span style="color: #339933;">=</span> String<span style="color: #339933;">.</span><span style="color: #990000;">Empty</span><span style="color: #339933;">;</span>
        try
        <span style="color: #009900;">&#123;</span>
            c <span style="color: #339933;">=</span> Application<span style="color: #339933;">.</span>GetCookie<span style="color: #009900;">&#40;</span>uri<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        catch <span style="color: #009900;">&#40;</span>Exception<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #666666; font-style: italic;">//set new cookie here</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #b1b100;">return</span> c<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> Dictionary<span style="color: #339933;">&lt;</span>string<span style="color: #339933;">,</span> string<span style="color: #339933;">&gt;</span> GetAuthentification<span style="color: #009900;">&#40;</span>string cookie<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">var</span> username <span style="color: #339933;">=</span> cookie<span style="color: #339933;">.</span>Substring<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> cookie<span style="color: #339933;">.</span>IndexOf<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Password=&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>Replace<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Username=&quot;</span><span style="color: #339933;">,</span> string<span style="color: #339933;">.</span><span style="color: #990000;">Empty</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">var</span> password <span style="color: #339933;">=</span> cookie<span style="color: #339933;">.</span>Substring<span style="color: #009900;">&#40;</span>cookie<span style="color: #339933;">.</span>IndexOf<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Password=&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>Replace<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Password=&quot;</span><span style="color: #339933;">,</span> string<span style="color: #339933;">.</span><span style="color: #990000;">Empty</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        Dictionary<span style="color: #339933;">&lt;</span>string<span style="color: #339933;">,</span> string<span style="color: #339933;">&gt;</span> auth <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Dictionary<span style="color: #339933;">&lt;</span>string<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>
        auth<span style="color: #339933;">.</span>Add<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Username&quot;</span><span style="color: #339933;">,</span> username<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        auth<span style="color: #339933;">.</span>Add<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Password&quot;</span><span style="color: #339933;">,</span> password<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">return</span> auth<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<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/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5iaWdnbGUuZGU=">Mario Priebe</a>.</p> <img src="http://www.biggle.de/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=6306" width="1" height="1" style="display: none;" /><h2  class="related_post_title">Ähnliche Beiträge</h2><ul class="related_post"><li>24. Juli 2011 -- <a href="http://www.biggle.de/blog/databindings-debuggen-wpf" title="DataBindings debuggen &#8211; WPF">DataBindings debuggen &#8211; WPF</a></li><li>23. Juli 2011 -- <a href="http://www.biggle.de/blog/gemeinsamen-validation-style-fr-controls-wpf" title="Gemeinsamen Validation Style f&uuml;r Controls &#8211; WPF">Gemeinsamen Validation Style f&uuml;r Controls &#8211; WPF</a></li><li>25. Juni 2011 -- <a href="http://www.biggle.de/blog/enumeration-in-einer-combobox-darstellen-wpf-quicky" title="Enumeration in einer ComboBox darstellen &#8211; WPF Quicky">Enumeration in einer ComboBox darstellen &#8211; WPF Quicky</a></li><li>6. März 2011 -- <a href="http://www.biggle.de/blog/multibinding-die-zweite" title="MultiBinding die Zweite">MultiBinding die Zweite</a></li><li>14. Februar 2011 -- <a href="http://www.biggle.de/blog/doppelklick-im-datagrid-abfangen-wpf-quicky" title="Doppelklick im DataGrid abfangen &#8211; WPF Quicky">Doppelklick im DataGrid abfangen &#8211; WPF Quicky</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.biggle.de/blog/cookies-in-einer-wpf-applikation/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

