WPF - DataTemplate/Value Converter for hyperlink in TextBlock -
I have a list box showing a list of people's names, emails, departments etc. There is a Datamapplet in which some text blocks are wrapping the hyperlink to display one of these textbars to display each asset such as:
& lt; TextBlock & gt; & Lt; Hyperlink navigatry = "{email binding}" & gt; & Lt; Text block text = "{binding email}" /> & Lt; / Hyperlink & gt; & Lt; / TextBlock & gt; It works fine, but if that person does not have an email address, then the textbox does not fall automatically. So I wrote a value converter and in style (like simplified) is used:
string s = (string) value; If (S == "") {return visibility. Collapsed; } Return visibility View; And this is the style using ValueConverter:
style x: key = "ResultItemTextBoxStyle" & gt; & Lt; Setter Property = "TextBlock" Visibility "value =" {Binding Path = Text, Relative Soros = {Relative Asher}}, Converter = {Static Resources StrongVisionhip Convent}} "/> & Lt; / Style & gt; And I added the style to call the converter for the textbol:
& lt; TextBlock style = "{StaticResource ResultItemTextBoxStyle}" & gt; & Lt; Hyperlink navigatry = "{email binding}" & gt; & Lt; Text block text = "{binding email}" /> & Lt; / Hyperlink & gt; & Lt; / TextBlock & gt; The email address is never displayed after this change - in the value converter, the TextBox text is always empty and gives visibility. Collapsed This hyperlink is evaluating text text before loading or something like that ...
Please help me out to do it one out.
Thank you!
You typed the converter text to TextBlock Comparing is empty, internal not a text of hyperlink I think that you really want to set relative tire to child hyperlink But I do not think this is possible.
Are you sure this is the TextBlock shape that has not collapsed? If you put the style on the hyperlink (or its inner TextBlock ), maybe it still works?
Edit: Hyperlink does not have visibility , so the style will not help by moving it forward, unfortunately. The only other option that I can think of is to create a custom control that comes from TextBlock , and it has hyperlink and TextBlock If you add it to email dependency property , then you can use it to determine whether the control should be visible or not, and the hyperlink Value for and its inner TextBlock . It seems that it should be a better way to handle it, but I can not think of some time.
Comments
Post a Comment