相关疑难解决方法(0)

MVVM将EventArgs作为命令参数传递

我正在使用Microsoft Expression Blend 4
我有一个浏览器..,

[XAML] ConnectionView"后面的空代码"

        <WebBrowser local:AttachedProperties.BrowserSource="{Binding Source}">
            <i:Interaction.Triggers>
                <i:EventTrigger>
                    <i:InvokeCommandAction Command="{Binding LoadedEvent}"/>
                </i:EventTrigger>
                <i:EventTrigger EventName="Navigated">
                    <i:InvokeCommandAction Command="{Binding NavigatedEvent}" CommandParameter="??????"/>
                </i:EventTrigger>
            </i:Interaction.Triggers>
        </WebBrowser>  
Run Code Online (Sandbox Code Playgroud)

[C#] AttachedProperties类

public static class AttachedProperties
    {
        public static readonly DependencyProperty BrowserSourceProperty = DependencyProperty . RegisterAttached ( "BrowserSource" , typeof ( string ) , typeof ( AttachedProperties ) , new UIPropertyMetadata ( null , BrowserSourcePropertyChanged ) );

        public static string GetBrowserSource ( DependencyObject _DependencyObject )
        {
            return ( string ) _DependencyObject . GetValue ( BrowserSourceProperty …
Run Code Online (Sandbox Code Playgroud)

browser wpf eventargs expression-blend

60
推荐指数
6
解决办法
9万
查看次数

MVVM:查看导航无法正常工作

我使用Brian Noyes的Pluralsight课程,"WPF MVVM In Depth"作为我的主要来源,他所展示的作品非常出色.

但是,我没有根据在UtilitiesView上单击的按钮切换视图,而是希望根据工具栏按钮(构成VS 2015扩展包的一部分)切换视图,用户可以在其中选择特定实例.

UtilitiesView是由包扩展打开的窗口上的用户控件.所以这是UtilitiesView中的xaml:`

<UserControl.Resources>
    <DataTemplate DataType="{x:Type engines:CalcEngineViewModel}">
        <engines:CalcEngineView/>
    </DataTemplate>
    <DataTemplate DataType="{x:Type engines:TAEngineViewModel}">
        <engines:TAEngineView/>
    </DataTemplate>
</UserControl.Resources>

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="auto" />
        <RowDefinition Height="*" />                         
    </Grid.RowDefinitions>
    <Grid x:Name="NavContent">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width ="*"/>
            <ColumnDefinition Width ="*"/>
            <ColumnDefinition Width ="*"/>
        </Grid.ColumnDefinitions>
        <Button Content="Calc"
                Command ="{Binding ChangeViewModelCommand}"
                CommandParameter="CalculationEngine"
                Grid.Column="0"/>
        <Button Content="TA"
                Command ="{Binding ChangeViewModelCommand}"
                CommandParameter="TAEngine"
                Grid.Column="1"/>

    </Grid>
    <Grid x:Name="MainContent"
        Grid.Row="1">
        <ContentControl Content="{Binding CurrentEngineViewModel}"/>
    </Grid>

</Grid>
</UserControl>`
Run Code Online (Sandbox Code Playgroud)

可以看出,有两个按钮通过绑定到ChangeViewModelCommand并传递字符串值("CalculationEngine"或"TAEngine")来切换View.

这是UtilitiesViewModel.cs类:

 public class UtilitiesViewModel : BindableBase
{
    #region Fields

    public RelayCommand<string> ChangeViewModelCommand { …
Run Code Online (Sandbox Code Playgroud)

c# wpf xaml mvvm

13
推荐指数
1
解决办法
880
查看次数

如何在视图模型中获取鼠标位置

从MVVM设计模式来看,viewmodel不应该知道视图.但就我而言,我需要视图和模型,我的意思是:

在我的窗口中,我有一个Image组件.当鼠标移过Image组件并将其保存到我的模型中时,我想获得鼠标位置.

背后的代码是:

void Foo_MouseMove(objet sender, MouseEventArgs e)
{
  model.x = e.getPosition(this.imageBox).X; 
  model.y = e.getPosition(this.imageBox).Y;
}
Run Code Online (Sandbox Code Playgroud)

问题是:我需要this.imageBox和MouseEventArgs,所以两个View元素.

我的问题是:如何使用MVVM方法处理这种情况?

我使用MVVM轻量级框架

c# wpf mvvm

6
推荐指数
3
解决办法
5866
查看次数

如何在MVVM中处理Wpf DataGrid CellEditEnding事件?

MVVM不允许代码隐藏,因此事件处理.那么什么是MVVM通知单元格被更改的方式?

wpf datagrid mvvm

5
推荐指数
1
解决办法
3690
查看次数

使用带TabItem的命令

当我的TabControl的TabItem被选中时,我想调用一个Command.

有没有办法在不破坏MVVM模式的情况下完成它?

c# wpf command mvvm

5
推荐指数
2
解决办法
1万
查看次数

在 MVVM 中绑定事件并将事件参数作为命令参数传递

我想用 ViewModel 绑定一个事件。

我用了

clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity

我使用触发器相同

  <Canvas Grid.Row="2" Grid.Column="2" x:Name="InteractiveCanvas" Style="{StaticResource canvasChartStyle}" ClipToBounds="True" >
        <intr:Interaction.Triggers>
            <intr:EventTrigger EventName="MouseEnter">
                <intr:InvokeCommandAction Command="AppointmentEditing" />
            </intr:EventTrigger>
        </intr:Interaction.Triggers>
    </Canvas>
Run Code Online (Sandbox Code Playgroud)

但我需要使用事件参数。这里无法得到相同的结果。

在 wpf 中,有没有可能绑定事件并获取事件参数?不使用 MVVM lite 或 PRISM。

我只想获取事件参数

.net c# wpf mvvm

4
推荐指数
1
解决办法
6943
查看次数

WPF MVVM - 单击时更新下拉列表

我有一个下拉列表(ComboBox),显示计算机上可用的所有COM端口.现在,当您连接和断开设备时,端口会进出.

出于性能原因,我不想继续通话System.IO.Ports.SerialPort.GetPortNames(),而只是在用户点击Combobox时调用它?这可能吗?是否有MVVM方法来解决这个问题?

c# wpf combobox drop-down-menu

3
推荐指数
2
解决办法
5820
查看次数