I am wondering if there is a way to bind the current ContextMenu item to a property in WPF without first clicking on it.
For example:
<MenuItem MaxHeight="20"
HorizontalAlignment="left"
Header="Radio Group"
Name="cmRadio"
ItemsSource="{Binding RadioGroups, Mode=OneWay}" />
I'm hoping to be able to figure out what item the mouse is over before clicking.
Sorry for the lack of description ahead of time.
There are lots of "mouseover" events you could use, some totally in XAML.
Similar Problem
See farther down for the XAML answer.
Related
Sorry for my bad headline but I couldn't figure out a better one. Heck, I don't even know how to properly ask my question. But here it comes.
I have a custom control in WPF, let's call it Cell. This control does have a few dependency properties, one Text to show in the Cell and a few "decorative" properties for background color, foreground color and so on. If I use this Cell control stand-alone, everything works fine so far.
Then I have another custom control inheriting from ItemsControl, let's call it Field. This control should show a text and some Cells. it has some "decorative" properties for the text part as well. The information about showing Cells is given to the control by a DataTemplate, something like
<DataTemplate x:Key="CellTemplate"
DataType="...">
<ns:Cell Text="{Binding Text}"
Background="{Binding ...}" />
</DataTemplate>
...
<ns:Field ItemsSource="{Binding Cells}"
ItemTemplate="{StaticResource CellTemplate}" />
If I use this Field control stand-alone, everything works fine so far.
Now I want to show several Field controls at once. So I put an ItemsControl on my window and gave an ItemTemplate again, something like:
<DataTemplate x:Key="CellTemplate"
DataType="...">
<ns:Cell Text="{Binding Text}"
Background="{Binding ...}" />
</DataTemplate>
<DataTemplate x:Key="FieldTemplate"
DataType="...">
<ns:Field ItemsSource="{Binding Cells}"
ItemTemplate="{StaticResource CellTemplate}"
FieldText="{Binding Text}"
TextBackground="{Binding ...}" />
</DataTemplate>
<ItemsControl ItemsSource="{Binding Fields}"
ItemTemplate="{StaticResource FieldTemplate}" />
As long as I preview my WPF window everything works fine so far. Changing the values of some "decorative" properties at Cell level or at Field level is immediately shown in the preview.
But if I run my program it seems that all "decorative" properties at Cell level are ignored. I can see all my Fields with their respective texts and I can see every Cell in every Field with their respective texts. But all Cells are plain white. All set colors are not shown.
Snoop tells me, that every color is set to Transparent by the ParentTemplate.
Visual Studio doesn't show me any exceptions or any binding errors. So I'm kind of stuck at where or how I can find the error and fix it.
So I wanted to ask you, if you may have a hint for me.
Does this contruction with a DataTemplate containing a DataTemplate and both DataTemplates bind to it's DataContext work?
Or does it have something to do with maybe re-using Brush objects that shouldn't be re-used?
But why is it working in the preview?
I have several pushpins on the map. When i hover with my mouse over the pushpins i get a dialogbox with some information in it. Now i also want some additional information when i click on the same pushpin. But i can't really figure out how to do this. I tried some things but it didn't work...
This is my code:
<bing:MapItemsControl ItemsSource="{Binding Items}">
<bing:MapItemsControl.ItemTemplate>
<DataTemplate>
<bing:Pushpin bing:MapLayer.Position="{Binding Location}" Background="{Binding Color, Converter={StaticResource brushConverter}}">
<ToolTipService.ToolTip>
<StackPanel>
<TextBlock Text="{Binding Address}" />
<TextBlock Text="{Binding Description}" />
</StackPanel>
</ToolTipService.ToolTip>
</bing:Pushpin>
</DataTemplate>
</bing:MapItemsControl.ItemTemplate>
</bing:MapItemsControl>
</bing:Map>
Has somebody tried to do this or know how to do this, by far thanks!
I know this is an old question, but maybe it will shine a little light on the right solution, and help someone else, if not you.
As I understand, the Tooltip stuff is already working, you just want to handle the clicks.
So here are some suggestions:
1 - The novice solution:
You can handle the event from the code behind. Since only Buttons have the Click event, you can't use that, but I think MouseLeftButtonDown, or even better MouseLeftButtonUp are equally good for this. Of course, if you have different maps on different controls, you will have to repeat this code on every one of them.
2 - The advanced solution:
Use Behaviors! They are like tiny extensions that can cling on to controls and extend their functionality. In your place, I would put a Behavior on the Pushpins, that would open a panel to display the info you want. You can read more about this topic under the link above!
In a WPF window I got a CheckBox containing an image, like this:
<CheckBox>
<Image Source="/Bsoft.Clients.Warenwirtschaft;component/Resources/MyImage.png" />
</CheckBox>
Using this, the checkmark is displayed left to the image.
Is there an easy way to move the checkmark to below the image?
I do not know of an easy way to do this.
You could either use some panel and have a checkbox independent from your image...
<StackPanel>
<Image .../>
<CheckBox .../>
</StackPanel>
Which might not be too much trouble if encapsulated in a UserControl.
Or you change the ControlTemplate of the CheckBox, which is more difficult i think. Default templates can be found on MSDN.
I'am just coding some global gesture handlers for a wpf application. For example I am supposed to use right click as a trigger to proceed UI.
<Window.InputBindings>
<MouseBinding MouseAction="RightClick" Command="NavigationCommands.NextPage"/>
</Window.InputBindings>
But now the problem appears that <ListBox/> consumes all mouse button events. I did some research but didn't found an easy way to make it just be unaware of the right button. Did anybody ever had this problem and found a solution? Thanks in advance.
You should be able to prevent the ListBox from consuming the mouse clicks using the following:
<ListBox>
<ListBox.InputBindings>
<MouseBinding MouseAction="RightClick" Command="ApplicationCommands.NotACommand" />
</ListBox.InputBindings>
</ListBox>
My DataTemplate for my ListBox has a TextBlock in it. If I click on the TextBlock, I want it to change to a TextBox so I can edit it. Is there a good way to do this?
You may get some ideas here: Tim heuer's editable ListBox
You should be able to use two-way binding of the text. Then, any edits to the Text dependency property for the item should be reflected back to the original data object.
In your DataTemplate, you probably have something like
<TextBox Text="{Binding}" />
Could you try making this
<TextBox Text="{Binding Mode=TwoWay}" />
Unfortunately I am on a machine without the Silverlight SDK on it at the moment, so I can't verify if my syntax is correct on the binding.