标签: delegatecommand

ui什么时候脱离命令?

我真的对这个问题感到头疼.我有一个主窗口打开一个对话框.对话框关闭后,对话框中绑定的命令上的CanExecute方法仍在执行.这在我的应用程序中引起了一些严重的问题.

例:

MainWindow有一个带有点击处理程序的按钮.这是click事件处理程序:

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        DialogWindow window = new DialogWindow();
        window.ShowDialog();
    }
Run Code Online (Sandbox Code Playgroud)

在对话框中,我将一个项控件绑定到对话框窗口中的静态资源,列表中的每个项都有一个命令:

<Window.Resources>

    <Collections:ArrayList x:Key="itemsSource">
        <local:ItemViewModel Description="A"></local:ItemViewModel>
        <local:ItemViewModel Description="B"></local:ItemViewModel>
        <local:ItemViewModel Description="C"></local:ItemViewModel>
    </Collections:ArrayList>

    <DataTemplate DataType="{x:Type local:ItemViewModel}">
            <Button Grid.Column="1" Command="{Binding Path=CommandClickMe}" Content="{Binding Path=Description}" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}">
            </Button>
    </DataTemplate>

</Window.Resources>

<Grid>
    <ToolBar ItemsSource="{StaticResource itemsSource}"></ToolBar>
</Grid>
Run Code Online (Sandbox Code Playgroud)

这是viewmodel:

public class ItemViewModel
{
    private RelayWpfCommand<object> _commandClickMe;

    public RelayWpfCommand<object> CommandClickMe
    {
        get
        {
            if (_commandClickMe == null)
                _commandClickMe = new RelayWpfCommand<object>(obj => System.Console.Out.WriteLine("Hei mom"), obj => CanClickMe());

            return _commandClickMe;
        }
    } …
Run Code Online (Sandbox Code Playgroud)

wpf delegatecommand

6
推荐指数
1
解决办法
895
查看次数

是否有像scrollviewDidScroll这样的uipickerview委托方法?

我有一个自定义的UIPickerview,我不想使用datepicker.我想实现这样的功能:当用户向下/向上滚动小时时,AM/PM组件在小时滚动时切换.这意味着我需要在调用pickerView didSelectRow之前切换它.有没有办法做到这一点?

谢谢

iphone uipickerview delegatecommand

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

WPF ToggleButton和DelegateCommand

有没有办法确定是否ToggleButton通过DelegateCommands 检查/取消检查?

TIA,迈克

下面的XAML代码.我正在使用ItemsControl并绑定到一个集合.我基本上想要一种方法来获得每个按钮点击时的切换状态.

<ScrollViewer VerticalScrollBarVisibility="Auto">
    <ItemsControl ItemsSource="{Binding Modifiers, Mode=TwoWay}">
        <ItemsControl.Template>
            <ControlTemplate>
                <ScrollViewer ScrollViewer.VerticalScrollBarVisibility="Auto">
                    <WrapPanel Margin="10" Width="{TemplateBinding Width}"
                               Height="{TemplateBinding Height}" 
                               FlowDirection="LeftToRight" IsItemsHost="true">
                    </WrapPanel>
                </ScrollViewer>
            </ControlTemplate>
        </ItemsControl.Template>
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <ToggleButton FontSize="18" Opacity="0.8"
                              Command="{Binding DataContext.ModifierToggleCommand, 
                                        RelativeSource={RelativeSource FindAncestor,
                                        AncestorType={x:Type Views:ModifiersView}}}" 
                              CommandParameter="{Binding}" Height="80" Width="200" Margin="5"
                              Content="{Binding Path=ModifierName}" />
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>
</ScrollViewer>
Run Code Online (Sandbox Code Playgroud)

wpf commandbinding delegatecommand togglebutton

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

jQuery:live()和delegate()

我将click事件绑定到div元素,该元素是在单击按钮后创建的.我正在使用.live(),这是有效的.我听说,我不应该使用.live,而是.delegate().所以我试过了,但它不起作用,但是.live正在工作.

我的工作jQuery:

$(".myDiv").live("click",function () {
    var Pos = $(this).offset();
    $("#Container").css("left", Pos.left).css("top", Pos.top);
});
Run Code Online (Sandbox Code Playgroud)

不工作的jQuery:

$(".myDiv").delegate("div","click",function () {
    var Pos = $(this).offset();
    $("#Container").css("left", Pos.left).css("top", Pos.top);
});
Run Code Online (Sandbox Code Playgroud)

我的HTML为div

<div class="myDiv"></div>
Run Code Online (Sandbox Code Playgroud)

谁能告诉我,为什么代表不为我工作?

jquery delegatecommand

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

如何在基本ViewModel类中为所有DelegateCommand和DelegateCommand <T>调用RaiseCanExecuteChanged

我正在使用Prism和MVVM开发WPF应用程序.

该应用程序的要求之一是能够以不同的用户身份登录(具有不同的权限).

现在大多数权限都是简单的允许或禁止显示特定视图.所有这些都是在DelegateCommand某个时间实现的DelegateCommand<T>

如果用户有权显示特定视图,那么这些命令的CanExecute将返回true.我还有一个包含用户信息和权限的单一Sessionmanager.

当用户登录时,我使用EventAggregator触发事件.在所有ViewModel的基类中,我订阅了该事件,并使用了反射循环通过类型为DelegateCommand的VM的所有公共属性,并为该命令调用RaiseCanExecuteChanged.

        Type myType = this.GetType();
        IList<PropertyInfo> props = new List<PropertyInfo>(myType.GetProperties());

        foreach (PropertyInfo prop in props)
        {
            if (prop.PropertyType == typeof(DelegateCommand))
            {
                var cmd = (DelegateCommand)prop.GetValue(this, null);
                cmd.RasieCanExecuteChanged();
            }

        }
Run Code Online (Sandbox Code Playgroud)

这适用于所有非泛型DelegateCommand属性,但当然不会影响DelegateCommand<T>.

我的问题是如何确定属性是否为类型DelegateCommand<T>并转换为该特定类型才能调用RasieCanExecuteChanged?

c# reflection wpf mvvm delegatecommand

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

WPF PRISM 6 DelegateComand ObservesCanExecute

提前致谢!

我应该如何在PRISM 6的DelegateCommand中使用ObservesCanExecute?

public partial class  UserAccountsViewModel: INotifyPropertyChanged
{
    public DelegateCommand InsertCommand { get; private set; }
    public DelegateCommand UpdateCommand { get; private set; }
    public DelegateCommand DeleteCommand { get; private set; }

    public UserAccount SelectedUserAccount
    {
        get;
        set
        {
            //notify property changed stuff
        }
    }

    public UserAccountsViewModel()
    {
        InitCommands();
    }

    private void InitCommands()
    {
        InsertCommand = new DelegateCommand(Insert, CanInsert);  
        UpdateCommand = new DelegateCommand(Update,CanUpdate).ObservesCanExecute(); // ???
        DeleteCommand = new DelegateCommand(Delete,CanDelete);
    }

    //----------------------------------------------------------

    private void Update()
    {
        //...
    }

    private bool …
Run Code Online (Sandbox Code Playgroud)

wpf prism delegatecommand

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

DelegateCommand 抛出“指定的强制转换无效”

我想使用带有 bool 作为参数的 PRISM 委托命令。这是相关代码:

public class ChartViewModel : BindableBase
{
    public DelegateCommand<bool?> ChangeZoomPanCommand { get; private set; }

    private bool isInRealtimeMode;
    public bool IsInRealtimeMode
    {
        get { return isInRealtimeMode; }
        set
        {
            SetProperty(ref isInRealtimeMode, value);
            ChangeZoomPanCommand.RaiseCanExecuteChanged();
        }
    }

    private bool dragToZoom;
    public bool DragToZoom
    {
        get { return dragToZoom; }
        set { SetProperty(ref dragToZoom, value); }
    }


    public ChartViewModel()
    {
        ChangeZoomPanCommand = new DelegateCommand<bool?>(ExecuteChangeZoomPan, CanExecuteChangeZoomPan);
        IsInRealtimeMode = true;
        DragToZoom = true;
    }

    private bool CanExecuteChangeZoomPan(bool? arg)
    {
        return !IsInRealtimeMode; …
Run Code Online (Sandbox Code Playgroud)

wpf prism delegatecommand

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

DelegateCommand是否与"附加行为"相同?

我一直在使用CodePlex 的MVVM Visual Studio模板中的DelegateCommand.这非常适合使View能够在其ViewModel上执行命令.

我在某处读过MVVM中应该使用" 附加行为 ".据我所知,"附加行为"与DelegateCommand是相同类型的模式,但Silverlight使用它,因为它没有命令.

这是正确的?或者"附加行为"是什么样的不同,值得学习添加到DelegateCommand?

silverlight wpf mvvm delegatecommand

3
推荐指数
1
解决办法
2161
查看次数

Prism:必须显式调用RaiseCanExecuteChanged()

下面是一个非常简单的Prism.Wpf示例,DelegateCommand其中包含两个ExecuteCanExecute委托.

假设这CanExecute取决于某些属性.看起来Prism's DelegateCommand不会CanExecute在这个属性发生变化时自动重新评估条件,就像RelayCommand其他MVVM框架一样.相反,您必须在属性设置器中显式调用RaiseCanExecuteChanged().这会在任何非平凡的视图模型中导致大量重复代码.

有没有更好的办法?

ViewModel:

using System;
using Prism.Commands;
using Prism.Mvvm;

namespace PrismCanExecute.ViewModels
{
public class MainWindowViewModel : BindableBase
{
    private string _title = "Prism Unity Application";
    public string Title
    {
        get { return _title; }
        set { SetProperty(ref _title, value); }
    }
    private string _name;
    public string Name
    {
        get { return _name; }
        set
        {
            SetProperty(ref _name, value);

            // Prism doesn't track …
Run Code Online (Sandbox Code Playgroud)

wpf prism mvvm delegatecommand

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