Probably it's just too late already, and I am slow, but I was confused with DisplayMemberPath and TextSearch.TextPath properties.
First, I added some objects to ComobBox.Items. Not using XML, I did it dynamically from C#. It worked find on Vista computer, but then it didn't work under XP. I just got empty values instead of value of ToString() method.
OK, I looked in my favorite book WPF Unleashed, and found that TextSearch.TextPath should be used. Well, it didn't help. It took me a while until I got to try old familiar DisplayMemberPath property and then it worked.
So, the question I have now is why TextSearch.TextPath didn't work? Or if asked in more general way, what are the rules. When I am supposed to use DisplayMemberPath and when TextSearch.TextPath. Anybody?
Here I will post problems I and my colleagues met and solutions we found.
Friday, September 19, 2008
ComboBox - DisplayMemberPath or TextSearch.TextPath
Wednesday, September 10, 2008
Hyperlinks in WPF Continued
I wrote before about using hyperlinks in WPF. For my new side project I need to switch from hypertext to the simple text depending on availability of URL. Switching to simple text seemed easy, just assigning text value to the Text property worked. Switching back was not obvious for me.
Then I found that TextBlock has Inlines property. The code became this:
if (!string.IsNullOrEmpty(uri))
{
if (!string.IsNullOrEmpty(value))
tHypertext.Inlines.Add(value);
tHypertext.NavigateUri = new Uri(uri);
tTextBlock.Inlines.Clear();
tTextBlock.Inlines.Add(tWord);
}
else
{
tTextBlock.Text = value;
tHypertext.NavigateUri = null;
}
Where TextBlock and Hypertext are from previouse example
Thursday, September 04, 2008
Keyboard.Modifiers sometimes doesn't work
There are many examples how to implement keyboard hooks in .NET. The one I used as example is http://blogs.vertigo.com/personal/ralph/Blog/archive/2007/02/12/wpf-low-level-keyboard-hook-sample.aspx
There is very important comment there that says Keyboard.Modifier property does not return correct values. First, I wanted to avoid linking to System.Windows.Form assembly and didn't pay much attention go this comments. Well, it didn't work. I had come back to using System.Windows.Forms.Control.ModifierKeys. To make interface more WPF compatible I just converted value this way:
System.Windows.Forms.Keys m = System.Windows.Forms.Control.ModifierKeys;
ModifierKeys m2 = ModifierKeys.None;
if ((m & System.Windows.Forms.Keys.Control) != 0)
m2 = m2 | ModifierKeys.Control;
if ((m & System.Windows.Forms.Keys.Alt) != 0)
m2 = m2 | ModifierKeys.Alt;
if ((m & System.Windows.Forms.Keys.Shift) != 0)
m2 = m2 | ModifierKeys.Shift;
if ((m & System.Windows.Forms.Keys.Apps) != 0)
m2 = m2 | ModifierKeys.Windows;