How can I set the text of a WPF Hyperlink via data binding?

后端 未结 3 1981
臣服心动
臣服心动 2020-12-07 14:18

In WPF, I want to create a hyperlink that navigates to the details of an object, and I want the text of the hyperlink to be the name of the object. Right now, I have this:

3条回答
  •  旧巷少年郎
    2020-12-07 14:57

    It looks strange, but it works. We do it in about 20 different places in our app. Hyperlink implicitly constructs a if you put text in its "content", but in .NET 3.5 won't let you bind to it, so you've got to explicitly use a TextBlock.

    
        
            
        
    
    

    Update: Note that as of .NET 4.0 the Run.Text property can now be bound:

    
    

提交回复
热议问题