标签: binding

WPF图像裁剪和绑定

我有一个显示一部分图像的简单网格。

 <Grid x:Name="back_side" Margin="-1" RenderTransformOrigin="0.5,0.5" RenderTransform="{Binding ScaleTransformBack}" Width="Auto">
        <Image Source="/NameSpace;component/Resources/image.jpg" Stretch="Fill">
            <Image.Clip>
                <RectangleGeometry Rect="{Binding RectGeo}"/>
            </Image.Clip>
        </Image>
    </Grid>
Run Code Online (Sandbox Code Playgroud)

我也尝试在后面的代码中直接绑定到RectangleGeometry。该剪辑似乎不想工作。有什么建议么?任何人都具有将剪辑绑定到图像的经验吗?

我需要能够以编程方式在多个控件上分割特定图像。使用剪辑作为要显示的每个控件的计算部分。

c# wpf binding

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

淘汰赛及其绑定

我有两个复选框,我希望这些复选框的值相互依赖.当我检查第一个复选框时,第二个是取消选中,当我取消选中第一个时,第二个被检查,反之亦然.我可以用jQuery做这个:例子.

$('input').on('change', 
     function() {         
         var anotherId = $(this).attr('id') == 'first' ? 'second' : 'first';        
         if($(this).is(':checked'))
             $('[id="' + anotherId + '"]').removeAttr('checked');
         else 
             $('[id="' + anotherId + '"]').attr('checked', 'true');
     });
Run Code Online (Sandbox Code Playgroud)

但这不是我想的最好的方式.我知道我可以用knockout.js来做,但不知道怎么做.你能帮我解决这个问题吗?

html binding knockout.js

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

带有复选框的敲除问题并检查并更改绑定

我刚刚发现了淘汰赛(3.0和3.1)和复选框的问题

问题是,复选框的更改事件绑定不会在不同的浏览器中一致地发生.

请参阅下面的代码

<table >
  <tr> 
    <td >
      <input type="checkbox" data-bind='checked: CheckVal, event: { change: refresh }' />
    </td>
    <td>Check Value in checked binding: <span data-bind="text: CheckVal"></span> 
    </td>
  </tr>
  <tr>
      <td></td>
    <td>Check Value in changed event binding: <span data-bind="text: CheckValChanged"></span> 
    </td>
    </tr>        
</table>
Run Code Online (Sandbox Code Playgroud)

和javascript

function MainViewModel() {
    var self = this;
    this.CheckVal = ko.observable(true);
    this.CheckValChanged = ko.observable(true);

    this.refresh = function() {
        self.CheckValChanged(self.CheckVal());
    }
}

viewModel = new MainViewModel();
ko.applyBindings(viewModel);
Run Code Online (Sandbox Code Playgroud)

在Firefox中,更改事件绑定发生在复选框值更改后,因此在更改事件处理程序中,我们可以读取复选框的实际值(即,如果选中复选框,则绑定字段的值为value = true).

在所有其他浏览器中(我使用Chrome,IE 11,Opera和Safari测试过),更改事件绑定似乎在实际更改绑定字段的值之前发生(即,选中复选框,在更改处理程序中读取的值)是false,如果未选中,则读取的值为true)

你可以在http://jsfiddle.net/bzamfir/su6SW/2/看到这个问题.

问题不仅在于浏览器中的行为不一致,而且对于大多数浏览器而言,这似乎是违反直觉的:事件是变化 …

data-binding binding onchange checked knockout.js

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

WPF:UI未更新绑定对象中的值更改

我对WPF比较新,并且遇到数据绑定问题.我将用户控件的依赖属性绑定到我的代码后面的类属性.在我的代码中实现类实体的过程中,UI通过INotifyPropertyChanged成功更新.然而,当随后更改OnPropertyChangedEventHandler后面的代码中的值时,但OnPropertyChanged方法不再回答这个问题.详情如下.如果有人能给我一些提示我做错了,那就太好了.

我实现了一个用户控件,我绑定到代码后面的部分类的属性CurrentAccProp.DiscountRate:

<local:doubleUEdit x:Name="InterestRate" LabelField="Interest rate" MinimumValue="0" MaximumValue="1" FormatStringForNumbers="P2" IncrementSize="0.01" UncertainValue="{Binding ElementName=RibbonWindow, Path=CurrentAccProp.DiscountRate, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
Run Code Online (Sandbox Code Playgroud)

CurrentAccProp是一个实例的类实现INotifyPropertyChanged以通知UI有关值的更改

//Event to inform data grid about changes
    public event PropertyChangedEventHandler PropertyChanged;
    private void OnPropertyChanged(string propertyName)
    {
        PropertyChangedEventHandler handler = PropertyChanged;
        if (handler != null)
        {
            handler(this, new PropertyChangedEventArgs(propertyName));
        }
    }
Run Code Online (Sandbox Code Playgroud)

在DiscountRate属性的setter中调用OnPropertyChanged:

doubleU discountingrate;
    public doubleU DiscountRate 
    { 
        get {return discountingrate;} 
        set 
        {
            discountingrate = value; 
            OnPropertyChanged("DiscountingRate");
        } 
    }
Run Code Online (Sandbox Code Playgroud)

我绑定到的用户控件的属性是作为依赖项属性实现的:

    //Property for data binding to doubleU
    [Description("The formatstring for the double boxes"), Category("Default")]
    public doubleU …
Run Code Online (Sandbox Code Playgroud)

c# wpf binding inotifypropertychanged

0
推荐指数
2
解决办法
2162
查看次数

根据Angular中的值更改了有界值

我对来自$ http请求的数组进行了ng-repeat.我有一个设置来显示我的网站上的数组的所有细节.

<div ng-repeat="i in data">
  <h2 id="price">€ {{i.total_price.EUR}}</h2>
  <div class="col-md-12" >
     {{i.changes}}
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

data是请求中数组的名称.i.changes给了我一个号码.但是,我希望i.changes输出这个数字,除非有数字0,然后我希望它输出'none'而不是0.我将如何进行?

binding xmlhttprequest angularjs angularjs-ng-repeat

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

ng-show不同时更新

这是一个有角度的问题,有ng-show和bindings.

我有2个字段,我不想同时显示.一个是显示"show"是真的,另一个是什么时候它是假的.

我有一个下拉列表,在选择某个选项时会更改此"显示"值.

但事情就是这样,两个人在同一时间出现的时刻非常短暂,即使他们不应该.怎么可能,以及如何解决这个问题?

binding angularjs ng-show

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

绑定到静态类的静态列表

我有静态类,当前的交易信息如下:

public static class BKM 
{
   public static List<Ticket> Tickets {get;set;}
}
Run Code Online (Sandbox Code Playgroud)

我想绑定到XAML中的Tickets.Count属性.

当我输入这样的东西

<TextBlock Text="{Binding Source={x:Static p:BKM.Tickets.Count}}" />
Run Code Online (Sandbox Code Playgroud)

其中p是

xmlns:p="clr-namespace:TicketApplication"
Run Code Online (Sandbox Code Playgroud)

我收到错误

错误22不支持嵌套类型:BKM.Tickets.
错误21找不到类型'BKM.Tickets'.请注意,类型名称区分大小写.
错误23无法在目标类型上找到成员"计数".

c# wpf binding list

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

命令参数Datagrid SelectedItems为空

因此,我从xaml中找到了这个答案Pass命令参数,我认为这是我了解的大多数方法。我遇到的问题是,当我在数据网格中选择一行时,它会触发命令,但所选项目为null。

我不知道并且怀疑是问题所在,我应该将所选项目传递给哪种类型的视图模型?目前,我正在使用IList,如我的viewmodel代码所示:

namespace Project_Manager.ViewModel
{
public class ProjectSummaryViewModel : ObservableObject
{
    public ProjectSummaryViewModel()
    {
        ProjectSummary = DatabaseFunctions.getProjectSummaryData();
    }

    private ObservableCollection<ProjectSummaryModel> projectsummary;
    public ObservableCollection<ProjectSummaryModel> ProjectSummary
    {
        get { return projectsummary; }
        set
        {
            projectsummary = value;
            OnPropertyChanged("ProjectSummary");
        }
    }

    public ICommand DeleteRowCommand
    {
        get { return new ParamDelegateCommand<IList<ProjectSummaryModel>>(DeleteRow); }
    }

    private void DeleteRow(IList<ProjectSummaryModel> projectsummaryselected)
    {
        string name = projectsummaryselected[0].ProjectName;
    }
}
}
Run Code Online (Sandbox Code Playgroud)

数据网格的XAML视图代码如下所示:

<Window x:Class="Project_Manager.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">

<!--<Window.Resources>
    <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
</Window.Resources>-->

    <Grid>
    <Grid.RowDefinitions> …
Run Code Online (Sandbox Code Playgroud)

wpf binding datagrid mvvm commandparameter

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

IsEnabled绑定更新后按钮未启用

我有一堂课叫做Document

public class Document : INotifyPropertyChanged
{                  
    public event PropertyChangedEventHandler PropertyChanged;
    private void NotifyPropertyChanged(string propertyName)
    {
        if (PropertyChanged != null)
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
    }             

    private string oldId;
    public string OldId
    {
        get { return oldId; }
        set { id = value; }
    }

    private string id;
    public string Id
    {
        get { return id; }
        set { 
            id = value;
            NotifyPropertyChanged("HasChanged");
        }
    }

    private string path;
    public string Path
    {
        get { return path; }
        set { path = …
Run Code Online (Sandbox Code Playgroud)

c# wpf binding button

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

MVVM ViewModel和属性类型(PresentationCore.dll)

我们可以在ViewModel中使用针对UI/UI框架的程序集中的类吗?

今天我讨论了一个问题,其中一个人非常执着,不能在PresentationModel中使用来自PresentationCore.dll的类.(好像他以前没有使用过ICommand)但是这样对吗?

因为我理解MVVM只是一种解耦View&ViewModel的模式?它没有说明我可以在ViewModel中使用什么类型的类,只要它们不创建视图(ViewModel没有直接引用视图或任何有关视图的特定实现或类型的知识).

请不要回答这是一个好的做法,我只是想明确MVVM.

c# data-binding wpf binding mvvm

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