|
Here[^] is an editor which could be of some assistance to you.
|
|
|
|
|
I'm using the Galasoft library to attempt to wire up event handling between a view and a viewmodel. There's a discussion of it here[^].
I have a list of customers defined as:
<ListBox ItemsSource="{Binding Customers}"
Grid.Row="0">
<i:Interaction.Triggers>
<i:EventTrigger EventName="ListBoxItem.MouseDoubleClick">
<g:EventToCommand Command="{Binding ListItemDoubleClickCommandd}" PassEventArgsToCommand="True" />
</i:EventTrigger>
</i:Interaction.Triggers>
</ListBox>
In the code behind I have:
private ICommand _ListItemDoubleClickCommand;
public ICommand ListItemDoubleClickCommandd
{
get
{
if (_ListItemDoubleClickCommand == null)
{
_ListItemDoubleClickCommand = new RelayCommand(listDoubleClicked);
}
return _ListItemDoubleClickCommand;
}
}
private void listDoubleClicked()
{
}
When I double click a list item, nothing happens. The listDoubleClicked method is never called.
Now, I also added a rectangle:
<Rectangle Fill="LightGray"
Stroke="Black"
Width="200"
Height="100"
Grid.Row="1">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseEnter">
<g:EventToCommand Command="{Binding RectangleMouseEnterCommand, Mode=OneWay}"
MustToggleIsEnabledValue="True" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Rectangle>
and in the code behind:
private ICommand _RectangleMouseEnterCommand;
public ICommand RectangleMouseEnterCommand
{
get
{
if (_RectangleMouseEnterCommand == null)
{
_RectangleMouseEnterCommand = new RelayCommand(rectangleMouseEnter);
}
return _RectangleMouseEnterCommand;
}
}
private void rectangleMouseEnter()
{
}
The rectangleMouseEnter method does get called. This means my list is wired wrong.
If I change "ListBoxItem.MouseDoubleClick" to "MouseEnter", then it fires. Anyone see what I'm doing wrong?
Thanks
Everything makes sense in someone's mind
|
|
|
|
|
Didn't we answer this same exact question a few weeks ago? You can't handle nested events like that. You can only trap ListBox events there. If you want to trap ListBoxItem events, you need to add that to a ListBoxItem style.
|
|
|
|
|
I don't remember. But I took that code straight from his site. I think the reason he had it there is that it seems that you can't do
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:g="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.WPF4
.
.
.
<Style x:Key="ListBoxItemStyle" TargetType="{x:Type ListBoxItem}">
<Style.Triggers>
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseDoubleClick">
<g:EventToCommand Command="{Binding ListItemDoubleClickCommandd}"
PassEventArgsToCommand="True" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Style.Triggers>
</Style>
The style doesn't like this. I'm not sure of the right way to code this. Any ideas?
Everything makes sense in someone's mind
|
|
|
|
|
 LOL, you were the one who asked the question . Anyways, you need to attach the interaction triggers to a Visual, so you need to include the control template unfortunately. The interaction triggers are buried a few lines down . This does seem a little messy. Your other option is to have a reusable control that forwards the ListBoxItem event to the parent ListBox. That's what I do in my framework, but its a bit more work. One other simpler option might be to just trap the ListBox double click and chase up the visual tree to make sure you clicked on a ListBoxItem.
<Style TargetType="{x:Type ListBoxItem}" BasedOn="{StaticResource {x:Type ListBoxItem}}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="true">
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
<i:Interaction.Triggers>
<!-- INSERT HERE -->
</i:Interaction.Triggers>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="true">
<Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/>
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsSelected" Value="true"/>
<Condition Property="Selector.IsSelectionActive" Value="false"/>
</MultiTrigger.Conditions>
<Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
</MultiTrigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
|
|
|
|
|
I want to add a second module for my Prism application WPF ,but i don't know what is the modification and where .
Thank you !!!
|
|
|
|
|
You need to add this new module inside the module catalog or load it via code - this link[^] talks about multiple ways to do this.
|
|
|
|
|
recently i moved my application from Winform to WPF, with winform when i choose files info my listbox the oped window to choose files different compare to the window now with WPF, can i change it to the one in Winform ?
here you can see the differents (WPF is the upper one)
http://www.imagebam.com/image/b575ff177434977[^]
|
|
|
|
|
You need to add a comctrl6 manifest to your app.
|
|
|
|
|
i didn't hear about Comctrl6 manifest
can you explain please ?
modified 2-Mar-12 13:32pm.
|
|
|
|
|
|
i didn't understand what i should do
|
|
|
|
|
Did you look at the link? It explains step by step
1) create the XML file as shown, you can get rid of the trustinfo section
2) call it yourappname.exe.manifest
3) set the post build command line as shown
|
|
|
|
|
|
I am currently developing uen WPF application I want to work with EFW, and I want to use the MVC architecture, I start with a small test, but it did not work .. I added a library or j 'I've added a WindowsForms want and when I add the time that reference to my project and I tried to post the form when click on the button help me please
|
|
|
|
|
You don't use MVC in WPF, you use MVVM.
|
|
|
|
|
I can use mvc with windows forms?
|
|
|
|
|
You can use whatever you want, I was just pointing out that WPF is specifically designed with MVVM in mind. That doesn't mean you have to use MVVM in WPF. That means that WPF + MVVM is going to provide you with the cleanest code.
|
|
|
|
|
|
i have one user control in which i have placed 15 label controls,now i want to bind their content with an observableCollection, in which i am filling string values.
let me clear once again, i am filling list which is observableCollection and want to show each item in list as label values in usercontrol.
sorry for bad English.
Regards
|
|
|
|
|
Why do you have exactly 15 labels? Are there never going to be more than 15 items in the collection? I'd recommend looking into the ListView control as an alternative.
|
|
|
|
|
Dear all,i want to know that there is any event occurs when children elements added to stackpanel?
|
|
|
|
|
i have a application with ComboBox, the combobox contain the network adapters from local machine and i want when the application start the combobox will be marked (my default is blue) as if I pressed the button myself.
how can i do it ?
|
|
|
|
|
I have a method which saves my main window's position using isolated storage. Another method is responsible for loading the position. Easy. I call the "save" when closing the main window and the "load" when opening the window. Easy
But when the saved postion is applied to the newly opening window, I see the window appear briefly in the default position before it is relocated to the desired saved postion. This is annoying. Any idea on how to prevent that?
Thx
|
|
|
|
|
When are you setting the window position? Sounds like you are setting it too late. Set it when the window is created, but before its shown.
|
|
|
|