WPF Button event not firing while Grid have PreviewMouseMove set
up vote
-1
down vote
favorite
I have button on the Grid that does not detects PreviewMouseLeftDown click event.
After some testing I figured that the problem is in <Grid PreviewMouseMove="onMouseMove" >
If I remove PreviewMouseMove="onMouseMove" part, then MouseDown event is detected, but i need that line of code, since I also have to detect mouse position inside that grid only.
XAML:
<Grid PreviewMouseMove="onMouseMove" Background="Transparent">
<ItemsControl Name="btnTableImageList">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Content="{Binding Content}"
Height="{Binding Height}"
Width="{Binding Width}"
Tag="{Binding Tag}"
Margin="{Binding Margin}"
Background="{Binding Background}"
HorizontalAlignment="Center"
PreviewMouseLeftButtonDown ="tblButton_MouseDown"
PreviewMouseLeftButtonUp ="tblButton_MouseUp"
Click="ClickHandlerTableBtn"
TextBlock.TextAlignment="Center" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
Any idea is welcomed. Thanks!
c# wpf
|
show 6 more comments
up vote
-1
down vote
favorite
I have button on the Grid that does not detects PreviewMouseLeftDown click event.
After some testing I figured that the problem is in <Grid PreviewMouseMove="onMouseMove" >
If I remove PreviewMouseMove="onMouseMove" part, then MouseDown event is detected, but i need that line of code, since I also have to detect mouse position inside that grid only.
XAML:
<Grid PreviewMouseMove="onMouseMove" Background="Transparent">
<ItemsControl Name="btnTableImageList">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Content="{Binding Content}"
Height="{Binding Height}"
Width="{Binding Width}"
Tag="{Binding Tag}"
Margin="{Binding Margin}"
Background="{Binding Background}"
HorizontalAlignment="Center"
PreviewMouseLeftButtonDown ="tblButton_MouseDown"
PreviewMouseLeftButtonUp ="tblButton_MouseUp"
Click="ClickHandlerTableBtn"
TextBlock.TextAlignment="Center" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
Any idea is welcomed. Thanks!
c# wpf
1
Even if you get an answer to this, I'm afraid you are going down the rabbit hole! You should learn about Commands and maybe refine your understanding about MVVM in general. If you feel you don't need that for your project, WPF might not be the right choice. The Bindings look very suspicious to me, especially the Binding of Tag to Tag...
– themightylc
Nov 22 at 6:44
@themightylc Can you please explain what is wrong with "Binding Tag"? I am using it for some data that is loaded from database, and since Buttons are generated during runtime, this is the way I am assigning data to certain button properties.
– Bodul
Nov 22 at 6:52
There is nothing "wrong" with it. It is impossible to explain the concept of MVVM in a few words. But try to answer this yourself: What is the Binding Source and if it's an class you designed yourself, then why did you call the source Property "Tag"?
– themightylc
Nov 22 at 7:22
I am guessing you are trying to achieve something like a gallery, maybe with pictures where you can move the pictures with your mouse but also something happens when you click on them, correct? Why would you need to Handle the Click Event, as well as MouseUp and MouseDown? Why does your Button have to be a Button?
– themightylc
Nov 22 at 7:24
1
to clarify: it's awesome you're trying to make something and WPF is a great framework. I love it. But I can spot one key problem in your second line of XAML and that is, your ItemsControl does not have an ItemsSource. Which means you must fill it programatically. Which means you create the "Content" Objects programatically. Which leads to the question why the Data in "Tag" is not in the Content already. I recommend you take a few hours and watch a few Videos on MVVM, especially the MVVM light toolkit. mvvmlight.net It can't be done in five minutes but it is well worth your time.
– themightylc
Nov 22 at 7:37
|
show 6 more comments
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
I have button on the Grid that does not detects PreviewMouseLeftDown click event.
After some testing I figured that the problem is in <Grid PreviewMouseMove="onMouseMove" >
If I remove PreviewMouseMove="onMouseMove" part, then MouseDown event is detected, but i need that line of code, since I also have to detect mouse position inside that grid only.
XAML:
<Grid PreviewMouseMove="onMouseMove" Background="Transparent">
<ItemsControl Name="btnTableImageList">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Content="{Binding Content}"
Height="{Binding Height}"
Width="{Binding Width}"
Tag="{Binding Tag}"
Margin="{Binding Margin}"
Background="{Binding Background}"
HorizontalAlignment="Center"
PreviewMouseLeftButtonDown ="tblButton_MouseDown"
PreviewMouseLeftButtonUp ="tblButton_MouseUp"
Click="ClickHandlerTableBtn"
TextBlock.TextAlignment="Center" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
Any idea is welcomed. Thanks!
c# wpf
I have button on the Grid that does not detects PreviewMouseLeftDown click event.
After some testing I figured that the problem is in <Grid PreviewMouseMove="onMouseMove" >
If I remove PreviewMouseMove="onMouseMove" part, then MouseDown event is detected, but i need that line of code, since I also have to detect mouse position inside that grid only.
XAML:
<Grid PreviewMouseMove="onMouseMove" Background="Transparent">
<ItemsControl Name="btnTableImageList">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Content="{Binding Content}"
Height="{Binding Height}"
Width="{Binding Width}"
Tag="{Binding Tag}"
Margin="{Binding Margin}"
Background="{Binding Background}"
HorizontalAlignment="Center"
PreviewMouseLeftButtonDown ="tblButton_MouseDown"
PreviewMouseLeftButtonUp ="tblButton_MouseUp"
Click="ClickHandlerTableBtn"
TextBlock.TextAlignment="Center" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
Any idea is welcomed. Thanks!
c# wpf
c# wpf
edited Nov 22 at 5:45
DestinatioN
1,2381326
1,2381326
asked Nov 22 at 5:43
Bodul
898
898
1
Even if you get an answer to this, I'm afraid you are going down the rabbit hole! You should learn about Commands and maybe refine your understanding about MVVM in general. If you feel you don't need that for your project, WPF might not be the right choice. The Bindings look very suspicious to me, especially the Binding of Tag to Tag...
– themightylc
Nov 22 at 6:44
@themightylc Can you please explain what is wrong with "Binding Tag"? I am using it for some data that is loaded from database, and since Buttons are generated during runtime, this is the way I am assigning data to certain button properties.
– Bodul
Nov 22 at 6:52
There is nothing "wrong" with it. It is impossible to explain the concept of MVVM in a few words. But try to answer this yourself: What is the Binding Source and if it's an class you designed yourself, then why did you call the source Property "Tag"?
– themightylc
Nov 22 at 7:22
I am guessing you are trying to achieve something like a gallery, maybe with pictures where you can move the pictures with your mouse but also something happens when you click on them, correct? Why would you need to Handle the Click Event, as well as MouseUp and MouseDown? Why does your Button have to be a Button?
– themightylc
Nov 22 at 7:24
1
to clarify: it's awesome you're trying to make something and WPF is a great framework. I love it. But I can spot one key problem in your second line of XAML and that is, your ItemsControl does not have an ItemsSource. Which means you must fill it programatically. Which means you create the "Content" Objects programatically. Which leads to the question why the Data in "Tag" is not in the Content already. I recommend you take a few hours and watch a few Videos on MVVM, especially the MVVM light toolkit. mvvmlight.net It can't be done in five minutes but it is well worth your time.
– themightylc
Nov 22 at 7:37
|
show 6 more comments
1
Even if you get an answer to this, I'm afraid you are going down the rabbit hole! You should learn about Commands and maybe refine your understanding about MVVM in general. If you feel you don't need that for your project, WPF might not be the right choice. The Bindings look very suspicious to me, especially the Binding of Tag to Tag...
– themightylc
Nov 22 at 6:44
@themightylc Can you please explain what is wrong with "Binding Tag"? I am using it for some data that is loaded from database, and since Buttons are generated during runtime, this is the way I am assigning data to certain button properties.
– Bodul
Nov 22 at 6:52
There is nothing "wrong" with it. It is impossible to explain the concept of MVVM in a few words. But try to answer this yourself: What is the Binding Source and if it's an class you designed yourself, then why did you call the source Property "Tag"?
– themightylc
Nov 22 at 7:22
I am guessing you are trying to achieve something like a gallery, maybe with pictures where you can move the pictures with your mouse but also something happens when you click on them, correct? Why would you need to Handle the Click Event, as well as MouseUp and MouseDown? Why does your Button have to be a Button?
– themightylc
Nov 22 at 7:24
1
to clarify: it's awesome you're trying to make something and WPF is a great framework. I love it. But I can spot one key problem in your second line of XAML and that is, your ItemsControl does not have an ItemsSource. Which means you must fill it programatically. Which means you create the "Content" Objects programatically. Which leads to the question why the Data in "Tag" is not in the Content already. I recommend you take a few hours and watch a few Videos on MVVM, especially the MVVM light toolkit. mvvmlight.net It can't be done in five minutes but it is well worth your time.
– themightylc
Nov 22 at 7:37
1
1
Even if you get an answer to this, I'm afraid you are going down the rabbit hole! You should learn about Commands and maybe refine your understanding about MVVM in general. If you feel you don't need that for your project, WPF might not be the right choice. The Bindings look very suspicious to me, especially the Binding of Tag to Tag...
– themightylc
Nov 22 at 6:44
Even if you get an answer to this, I'm afraid you are going down the rabbit hole! You should learn about Commands and maybe refine your understanding about MVVM in general. If you feel you don't need that for your project, WPF might not be the right choice. The Bindings look very suspicious to me, especially the Binding of Tag to Tag...
– themightylc
Nov 22 at 6:44
@themightylc Can you please explain what is wrong with "Binding Tag"? I am using it for some data that is loaded from database, and since Buttons are generated during runtime, this is the way I am assigning data to certain button properties.
– Bodul
Nov 22 at 6:52
@themightylc Can you please explain what is wrong with "Binding Tag"? I am using it for some data that is loaded from database, and since Buttons are generated during runtime, this is the way I am assigning data to certain button properties.
– Bodul
Nov 22 at 6:52
There is nothing "wrong" with it. It is impossible to explain the concept of MVVM in a few words. But try to answer this yourself: What is the Binding Source and if it's an class you designed yourself, then why did you call the source Property "Tag"?
– themightylc
Nov 22 at 7:22
There is nothing "wrong" with it. It is impossible to explain the concept of MVVM in a few words. But try to answer this yourself: What is the Binding Source and if it's an class you designed yourself, then why did you call the source Property "Tag"?
– themightylc
Nov 22 at 7:22
I am guessing you are trying to achieve something like a gallery, maybe with pictures where you can move the pictures with your mouse but also something happens when you click on them, correct? Why would you need to Handle the Click Event, as well as MouseUp and MouseDown? Why does your Button have to be a Button?
– themightylc
Nov 22 at 7:24
I am guessing you are trying to achieve something like a gallery, maybe with pictures where you can move the pictures with your mouse but also something happens when you click on them, correct? Why would you need to Handle the Click Event, as well as MouseUp and MouseDown? Why does your Button have to be a Button?
– themightylc
Nov 22 at 7:24
1
1
to clarify: it's awesome you're trying to make something and WPF is a great framework. I love it. But I can spot one key problem in your second line of XAML and that is, your ItemsControl does not have an ItemsSource. Which means you must fill it programatically. Which means you create the "Content" Objects programatically. Which leads to the question why the Data in "Tag" is not in the Content already. I recommend you take a few hours and watch a few Videos on MVVM, especially the MVVM light toolkit. mvvmlight.net It can't be done in five minutes but it is well worth your time.
– themightylc
Nov 22 at 7:37
to clarify: it's awesome you're trying to make something and WPF is a great framework. I love it. But I can spot one key problem in your second line of XAML and that is, your ItemsControl does not have an ItemsSource. Which means you must fill it programatically. Which means you create the "Content" Objects programatically. Which leads to the question why the Data in "Tag" is not in the Content already. I recommend you take a few hours and watch a few Videos on MVVM, especially the MVVM light toolkit. mvvmlight.net It can't be done in five minutes but it is well worth your time.
– themightylc
Nov 22 at 7:37
|
show 6 more comments
2 Answers
2
active
oldest
votes
up vote
0
down vote
I totally agree with themightylc, but also understand you... WPF and MVVM are not so "easy" to get used to, I do it for a year more or less, and still have a lot to learn.
In that kind of situation I only could advise you to read some tutorials about WPF, DataBinding and ObservableCollection and ViewModel (these are the keywords you need to know).
1) Create a ViewModel where you can define a ObservableCollection, ObservableCollection is kind of list, but using it you can update your View (almost) automaticaly.so when you launch your application, you will read the list of buttons you need to display, then add them to the ObservableCollection
for your tests will be something like that :
Button button1=new Button();
Button button2=new Button();
//define all dimensions/parameters of your button
MyObservableCollection.Add(button1);
MyObservableCollection.Add(button2);
Then in XAML you just need to specify the ItemsSource of ItemsControls(MyObservableCollection). doing like that you don't need anymore all description of buttons inside.
Then when you click to add a button(in your case), you just need to make in code behind something like
Button newButton=new Button();
newButton.Height=defaultHeight...//width, background etc...
MyObservableCollection.Add(newButton);
again, just for advise if WPF/MVVM is new to you, I would advise to begin with easier samples, make a small listview with simple objects inside, or a listbox.
Could also advise you these websites :
wpf-tutorial.com
www.wpftutorial.net
add a comment |
up vote
0
down vote
At the end this is actually working properly.
For test I have set up a label, and in MouseMove event i am sending Mouse Position to that label,lblCoord.Content = Mouse.GetPosition(Application.Current.MainWindow);
In case of MouseClick I am sending lblCoord.Content="MouseClick";
And in case of MouseDown I am sending lblCoord.Content="MouseDown";
.
I can see mouse coordinates in lblCoord, I can see MouseClick, but it never displayed MouseDown.
However, if i call MessageBox inside MouseDown event, everything works. So i guess that XAML <Grid> PreviewMouseMove="onMouseMove"
works even when I am not moving mouse so it is sending coords to a Label all the time and overwrites lblCoord.Content="MouseDown";
faster than I am able to see it.
The answer to this question is: Don't work with WPF and expect WinForms results...
Thanks to everybody for their time and effort!
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
I totally agree with themightylc, but also understand you... WPF and MVVM are not so "easy" to get used to, I do it for a year more or less, and still have a lot to learn.
In that kind of situation I only could advise you to read some tutorials about WPF, DataBinding and ObservableCollection and ViewModel (these are the keywords you need to know).
1) Create a ViewModel where you can define a ObservableCollection, ObservableCollection is kind of list, but using it you can update your View (almost) automaticaly.so when you launch your application, you will read the list of buttons you need to display, then add them to the ObservableCollection
for your tests will be something like that :
Button button1=new Button();
Button button2=new Button();
//define all dimensions/parameters of your button
MyObservableCollection.Add(button1);
MyObservableCollection.Add(button2);
Then in XAML you just need to specify the ItemsSource of ItemsControls(MyObservableCollection). doing like that you don't need anymore all description of buttons inside.
Then when you click to add a button(in your case), you just need to make in code behind something like
Button newButton=new Button();
newButton.Height=defaultHeight...//width, background etc...
MyObservableCollection.Add(newButton);
again, just for advise if WPF/MVVM is new to you, I would advise to begin with easier samples, make a small listview with simple objects inside, or a listbox.
Could also advise you these websites :
wpf-tutorial.com
www.wpftutorial.net
add a comment |
up vote
0
down vote
I totally agree with themightylc, but also understand you... WPF and MVVM are not so "easy" to get used to, I do it for a year more or less, and still have a lot to learn.
In that kind of situation I only could advise you to read some tutorials about WPF, DataBinding and ObservableCollection and ViewModel (these are the keywords you need to know).
1) Create a ViewModel where you can define a ObservableCollection, ObservableCollection is kind of list, but using it you can update your View (almost) automaticaly.so when you launch your application, you will read the list of buttons you need to display, then add them to the ObservableCollection
for your tests will be something like that :
Button button1=new Button();
Button button2=new Button();
//define all dimensions/parameters of your button
MyObservableCollection.Add(button1);
MyObservableCollection.Add(button2);
Then in XAML you just need to specify the ItemsSource of ItemsControls(MyObservableCollection). doing like that you don't need anymore all description of buttons inside.
Then when you click to add a button(in your case), you just need to make in code behind something like
Button newButton=new Button();
newButton.Height=defaultHeight...//width, background etc...
MyObservableCollection.Add(newButton);
again, just for advise if WPF/MVVM is new to you, I would advise to begin with easier samples, make a small listview with simple objects inside, or a listbox.
Could also advise you these websites :
wpf-tutorial.com
www.wpftutorial.net
add a comment |
up vote
0
down vote
up vote
0
down vote
I totally agree with themightylc, but also understand you... WPF and MVVM are not so "easy" to get used to, I do it for a year more or less, and still have a lot to learn.
In that kind of situation I only could advise you to read some tutorials about WPF, DataBinding and ObservableCollection and ViewModel (these are the keywords you need to know).
1) Create a ViewModel where you can define a ObservableCollection, ObservableCollection is kind of list, but using it you can update your View (almost) automaticaly.so when you launch your application, you will read the list of buttons you need to display, then add them to the ObservableCollection
for your tests will be something like that :
Button button1=new Button();
Button button2=new Button();
//define all dimensions/parameters of your button
MyObservableCollection.Add(button1);
MyObservableCollection.Add(button2);
Then in XAML you just need to specify the ItemsSource of ItemsControls(MyObservableCollection). doing like that you don't need anymore all description of buttons inside.
Then when you click to add a button(in your case), you just need to make in code behind something like
Button newButton=new Button();
newButton.Height=defaultHeight...//width, background etc...
MyObservableCollection.Add(newButton);
again, just for advise if WPF/MVVM is new to you, I would advise to begin with easier samples, make a small listview with simple objects inside, or a listbox.
Could also advise you these websites :
wpf-tutorial.com
www.wpftutorial.net
I totally agree with themightylc, but also understand you... WPF and MVVM are not so "easy" to get used to, I do it for a year more or less, and still have a lot to learn.
In that kind of situation I only could advise you to read some tutorials about WPF, DataBinding and ObservableCollection and ViewModel (these are the keywords you need to know).
1) Create a ViewModel where you can define a ObservableCollection, ObservableCollection is kind of list, but using it you can update your View (almost) automaticaly.so when you launch your application, you will read the list of buttons you need to display, then add them to the ObservableCollection
for your tests will be something like that :
Button button1=new Button();
Button button2=new Button();
//define all dimensions/parameters of your button
MyObservableCollection.Add(button1);
MyObservableCollection.Add(button2);
Then in XAML you just need to specify the ItemsSource of ItemsControls(MyObservableCollection). doing like that you don't need anymore all description of buttons inside.
Then when you click to add a button(in your case), you just need to make in code behind something like
Button newButton=new Button();
newButton.Height=defaultHeight...//width, background etc...
MyObservableCollection.Add(newButton);
again, just for advise if WPF/MVVM is new to you, I would advise to begin with easier samples, make a small listview with simple objects inside, or a listbox.
Could also advise you these websites :
wpf-tutorial.com
www.wpftutorial.net
answered Nov 22 at 8:47
Siegfried.V
141112
141112
add a comment |
add a comment |
up vote
0
down vote
At the end this is actually working properly.
For test I have set up a label, and in MouseMove event i am sending Mouse Position to that label,lblCoord.Content = Mouse.GetPosition(Application.Current.MainWindow);
In case of MouseClick I am sending lblCoord.Content="MouseClick";
And in case of MouseDown I am sending lblCoord.Content="MouseDown";
.
I can see mouse coordinates in lblCoord, I can see MouseClick, but it never displayed MouseDown.
However, if i call MessageBox inside MouseDown event, everything works. So i guess that XAML <Grid> PreviewMouseMove="onMouseMove"
works even when I am not moving mouse so it is sending coords to a Label all the time and overwrites lblCoord.Content="MouseDown";
faster than I am able to see it.
The answer to this question is: Don't work with WPF and expect WinForms results...
Thanks to everybody for their time and effort!
add a comment |
up vote
0
down vote
At the end this is actually working properly.
For test I have set up a label, and in MouseMove event i am sending Mouse Position to that label,lblCoord.Content = Mouse.GetPosition(Application.Current.MainWindow);
In case of MouseClick I am sending lblCoord.Content="MouseClick";
And in case of MouseDown I am sending lblCoord.Content="MouseDown";
.
I can see mouse coordinates in lblCoord, I can see MouseClick, but it never displayed MouseDown.
However, if i call MessageBox inside MouseDown event, everything works. So i guess that XAML <Grid> PreviewMouseMove="onMouseMove"
works even when I am not moving mouse so it is sending coords to a Label all the time and overwrites lblCoord.Content="MouseDown";
faster than I am able to see it.
The answer to this question is: Don't work with WPF and expect WinForms results...
Thanks to everybody for their time and effort!
add a comment |
up vote
0
down vote
up vote
0
down vote
At the end this is actually working properly.
For test I have set up a label, and in MouseMove event i am sending Mouse Position to that label,lblCoord.Content = Mouse.GetPosition(Application.Current.MainWindow);
In case of MouseClick I am sending lblCoord.Content="MouseClick";
And in case of MouseDown I am sending lblCoord.Content="MouseDown";
.
I can see mouse coordinates in lblCoord, I can see MouseClick, but it never displayed MouseDown.
However, if i call MessageBox inside MouseDown event, everything works. So i guess that XAML <Grid> PreviewMouseMove="onMouseMove"
works even when I am not moving mouse so it is sending coords to a Label all the time and overwrites lblCoord.Content="MouseDown";
faster than I am able to see it.
The answer to this question is: Don't work with WPF and expect WinForms results...
Thanks to everybody for their time and effort!
At the end this is actually working properly.
For test I have set up a label, and in MouseMove event i am sending Mouse Position to that label,lblCoord.Content = Mouse.GetPosition(Application.Current.MainWindow);
In case of MouseClick I am sending lblCoord.Content="MouseClick";
And in case of MouseDown I am sending lblCoord.Content="MouseDown";
.
I can see mouse coordinates in lblCoord, I can see MouseClick, but it never displayed MouseDown.
However, if i call MessageBox inside MouseDown event, everything works. So i guess that XAML <Grid> PreviewMouseMove="onMouseMove"
works even when I am not moving mouse so it is sending coords to a Label all the time and overwrites lblCoord.Content="MouseDown";
faster than I am able to see it.
The answer to this question is: Don't work with WPF and expect WinForms results...
Thanks to everybody for their time and effort!
answered Nov 23 at 16:51
Bodul
898
898
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53424549%2fwpf-button-event-not-firing-while-grid-have-previewmousemove-set%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Even if you get an answer to this, I'm afraid you are going down the rabbit hole! You should learn about Commands and maybe refine your understanding about MVVM in general. If you feel you don't need that for your project, WPF might not be the right choice. The Bindings look very suspicious to me, especially the Binding of Tag to Tag...
– themightylc
Nov 22 at 6:44
@themightylc Can you please explain what is wrong with "Binding Tag"? I am using it for some data that is loaded from database, and since Buttons are generated during runtime, this is the way I am assigning data to certain button properties.
– Bodul
Nov 22 at 6:52
There is nothing "wrong" with it. It is impossible to explain the concept of MVVM in a few words. But try to answer this yourself: What is the Binding Source and if it's an class you designed yourself, then why did you call the source Property "Tag"?
– themightylc
Nov 22 at 7:22
I am guessing you are trying to achieve something like a gallery, maybe with pictures where you can move the pictures with your mouse but also something happens when you click on them, correct? Why would you need to Handle the Click Event, as well as MouseUp and MouseDown? Why does your Button have to be a Button?
– themightylc
Nov 22 at 7:24
1
to clarify: it's awesome you're trying to make something and WPF is a great framework. I love it. But I can spot one key problem in your second line of XAML and that is, your ItemsControl does not have an ItemsSource. Which means you must fill it programatically. Which means you create the "Content" Objects programatically. Which leads to the question why the Data in "Tag" is not in the Content already. I recommend you take a few hours and watch a few Videos on MVVM, especially the MVVM light toolkit. mvvmlight.net It can't be done in five minutes but it is well worth your time.
– themightylc
Nov 22 at 7:37