Click here to Skip to main content
15,847,077 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have collection of objects inside DataGrid. One property is an URL inside a string.
I want to bind this property with a button, so when user clicks on a button, it opens browser and goes to the specified URL.

      <Button Click="{Binding ViewModelURL}">Go to link</Button> 

This Click example is obviously wrong, but I want to give you general idea what I want to achieve. I'm using MVVM pattern, so it probably should be done purely from XAML side. I kind of can't access that specific URL from code-behind (because I don't know which button was pressed).

What I have tried:

A lot of googling, but it appears no one ever attempted that.
Updated 4-Mar-21 1:03am

1 solution

I found this with Google: wpf - Binding Button click to a method - Stack Overflow[^]

Look at the first answer.
Share this answer
Member 15047625 4-Mar-21 6:18am    
But I don't know the link from code behind. I need to somehow bind it inside XAML.
#realJSOP 4-Mar-21 9:46am    
I don't think you can do it that way. Itwould be much simpler if you simply handled the event in your form i think.
Member 15047625 4-Mar-21 12:29pm    
I have went around it. Binded link to the Tag, and I'm reading the Tag inside Click method. Is it great? No. Does it work? Absolutely.
#realJSOP 4-Mar-21 12:38pm    
I think the Tag property is the most forgotten and neglected property in WPF. I often don't consider its use unless it's a last-resort situation.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900