标签: binding

将一个类绑定到多个接口作为单例

我有例如2个interfases IInterface1和IInterface2,

public interface IInterface1 {...}
public interface IInterface2 {...} 
Run Code Online (Sandbox Code Playgroud)

以及这些接口的一个实现ImplClass.

public class ImplClass : IInterface1, IInterface2 {...}
Run Code Online (Sandbox Code Playgroud)

我必须确保应用程序只有一个ImplClass实例,它将用作IInterface1和IInterface2.我正在使用ninject进行依赖注入.所以我的问题是:下面的代码是否符合我的要求?

...
Bind<IInterface1>().To<ImplClass>().Using<SingletonBehavior>();
Bind<IInterface2>().To<ImplClass>().Using<SingletonBehavior>();
...
Run Code Online (Sandbox Code Playgroud)

或者此代码将为eash接口创建2个ImplClass实例?

c# singleton binding dependency-injection ninject

18
推荐指数
2
解决办法
5112
查看次数

有没有办法刷新WPF中的所有绑定?

如果我的代码看起来有点像下面的代码,是否可以直接刷新所有绑定或我是否必须硬编码所有绑定刷新?

服务端:

[ServiceContract]
public interface IMyServiceContract {
    [OperationContract]
    MyDataContract GetData();
}
[ServiceBehavior]
public class MyService {
    [OperationBehavior]
    public MyDataContract GetData() {
        MyDataContract data = new MyDataContract();
        data.val1 = "123";
        data.val2 = "456";
        return data;
    }
}
[DataContract]
public class MyDataContract {
    [DataMember]
    public string val1;
    public string val2;
}
Run Code Online (Sandbox Code Playgroud)

客户端xaml(省略了名称空间样板代码):

<Window x:Class="MyWindow" DataContext="{Binding RelativeSource={RelativeSource Self}}" Title="{Binding Path=val1, Mode=OneWay}">
    <DockPanel>
        <TextBlock Text="{Binding Path=val1, Mode=OneWay}"/>
        <TextBlock Text="{Binding Path=val2, Mode=OneWay}"/>
    </DockPanel>
</Window>
Run Code Online (Sandbox Code Playgroud)

客户端代码behing:

public partial class MyWindow {
    MyServiceClient client = new MyServiceClient(); …
Run Code Online (Sandbox Code Playgroud)

.net c# wpf xaml binding

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

找不到WCF绑定错误?

我使用的是VSTS 2008 + C#+ .Net 3.0.我正在使用自托管的WCF.执行以下语句时,会出现以下绑定未找到错误.我发布了我的整个app.config文件,任何想法有什么问题?

ServiceHost host = new ServiceHost(typeof(MyWCFService));
Run Code Online (Sandbox Code Playgroud)

错误信息,

Configuration binding extension 'system.serviceModel/bindings/MyBinding' could not be found. Verify that this binding extension is properly registered in system.serviceModel/extensions/bindingExtensions and that it is spelled correctly.
Run Code Online (Sandbox Code Playgroud)

完整的app.config,

<?xml version="1.0"?>
<configuration>
  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="MyBinding"
            closeTimeout="00:00:10"
            openTimeout="00:00:20"
            receiveTimeout="00:00:30"
            sendTimeout="00:00:40"
            bypassProxyOnLocal="false"
            transactionFlow="false"
            hostNameComparisonMode="WeakWildcard"
            maxReceivedMessageSize="100000000"
            messageEncoding="Mtom"
            proxyAddress="http://foo/bar"
            textEncoding="utf-16"
            useDefaultWebProxy="false">
          <reliableSession ordered="false"
               inactivityTimeout="00:02:00"
               enabled="true" />
          <security mode="Transport">
            <transport clientCredentialType="Digest"
               proxyCredentialType="None"
               realm="someRealm" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <services>
      <service name="MyWCFService"
                behaviorConfiguration="mexServiceBehavior">
        <host>
          <baseAddresses>
            <add …
Run Code Online (Sandbox Code Playgroud)

c# wcf binding visual-studio-2008

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

在PHP中使用PDO绑定decimal/double/float值的最佳方法是什么?

看样子类的常量只有覆盖PDO::PARAM_BOOL,PDO::PARAM_INT并PDO::PARAM_STR进行绑定.你只是将decimal/float/double值绑定为字符串,还是有更好的方法来处理它们?

MySQLi允许'd'类型为double,令人惊讶的是PDO在许多其他方面看起来更好时没有等价物.

php mysql database binding pdo

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

将通用List <string>绑定到ComboBox

我有一个ComboBox,我想绑定一个通用的List.任何人都可以看到为什么下面的代码不起作用?绑定源中包含数据,但它不会填充ComboBox数据源.

FillCbxProject(DownloadData Down)
{
  BindingSource bindingSource = new BindingSource();
  bindingSource.DataSource = Down.ProjectList;
  cbxProjectd.DataSource = bindingSource;
}
Run Code Online (Sandbox Code Playgroud)

旁注:传递一个类的实例是不是很糟糕?

谢谢!

c# data-binding binding winforms

17
推荐指数
2
解决办法
8万
查看次数


Backbone.js事件绑定

我正在使用Backbone.js为每个模型的视图都有一个分段控件类型的UI元素.它们各自由具有少量li元素的ul组成.我想绑定一个事件,以便在单击其中一个元素时,我可以确定单击了哪个元素并使用适当的值更新模型.

问题是Backbone绑定事件(这些事件在视图的事件哈希中),使得回调函数中的"this"引用视图,而不是li元素.这意味着我无法确定单击了哪些li元素.如果我使用普通的jQuery绑定,我可以将"this"绑定到li元素,但是我不再跟踪模型了,所以我无法更新它.

jquery events binding callback backbone.js

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

在没有魔术字符串的情况下实现NotifyPropertyChanged

可能重复:
使用linq表达式的typesafe NotifyPropertyChanged

我正在研究一个庞大的团队应用程序,该应用程序正在以大量使用魔术字符串的形式NotifyPropertyChanged("PropertyName")- 在咨询Microsoft时的标准实现.我们还遭受了大量错误命名的属性(使用具有数百个存储的计算属性的计算模块的对象模型) - 所有这些属性都绑定到UI.

我的团队经历了许多与属性名称更改相关的错误,导致错误的魔术字符串和破坏绑定.我希望通过实现属性更改通知而不使用魔术字符串来解决问题.我发现.Net 3.5的唯一解决方案涉及lambda表达式.(例如:实现INotifyPropertyChanged - 是否存在更好的方法?)

我的经理非常担心转换的性能成本

set { ... OnPropertyChanged("PropertyName"); }
Run Code Online (Sandbox Code Playgroud)

至

set {  ... OnPropertyChanged(() => PropertyName); }
Run Code Online (Sandbox Code Playgroud)

提取名称的位置

protected virtual void OnPropertyChanged<T>(Expression<Func<T>> selectorExpression)
{
    MemberExpression body = selectorExpression.Body as MemberExpression;
    if (body == null) throw new ArgumentException("The body must be a member expression");
    OnPropertyChanged(body.Member.Name);
}
Run Code Online (Sandbox Code Playgroud)

考虑像电子表格这样的应用程序,当参数发生变化时,会在UI上实时重新计算和更新大约一百个值.是否会使此更改变得如此昂贵以至于会影响UI的响应能力?我现在甚至无法证明测试此更改的合理性,因为在各种项目和类中更新属性设置器需要大约2天.

wpf binding inotifypropertychanged .net-3.5

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

如何从.framework创建MonoTouch绑定

我下载了TouchDB,一个"适合嵌入移动或桌面应用程序的轻量级Apache CouchDB兼容数据库引擎",它给了我一堆.framework文件夹(CouchCocoa.framework,TouchDB.framework和TouchDBListener.framework).

我一直在阅读有关将Obj-C库绑定到MonoTouch的文章,它展示了如何绑定a.a,而不是如何绑定a .framework.

我如何为这些绑定.framework?或者我应该在使用之前以某种方式制作.a这些.framework(如果可能的话)?

- 编辑 -

相关:https://bitbucket.org/LouisBoux/touchdb-monotouchbinding

binding couchdb xamarin.ios couchcocoa

17
推荐指数
2
解决办法
5632
查看次数

WPF用户控件将数据绑定到用户控件属性

我有用户控制权:

XAML

<UserControl x:Class="controlmaker.checkButton"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         mc:Ignorable="d" 
         d:DesignHeight="114" d:DesignWidth="221">
<Grid Background="Aqua" >
    <CheckBox Content="CheckBox" Height="16" HorizontalAlignment="Left" Margin="58,24,0,0" Name="checkBox1" VerticalAlignment="Top" />
    <Button Content="{Binding buttText}" Height="23" HorizontalAlignment="Left" Margin="58,57,0,0" Name="button1" VerticalAlignment="Top" Width="75" />
</Grid>
</UserControl>
Run Code Online (Sandbox Code Playgroud)

代码背后

public partial class checkButton : UserControl
{
    public checkButton()
    {
        InitializeComponent();
    }


    public static readonly DependencyProperty buttTextProperty =
DependencyProperty.Register("buttText", typeof(String),
typeof(checkButton), new FrameworkPropertyMetadata(string.Empty));

    public String buttText
    {
        get { return GetValue(buttTextProperty).ToString(); }
        set { SetValue(buttTextProperty, value); }
    }


}
Run Code Online (Sandbox Code Playgroud)

和主窗口xaml

<Window x:Class="controlmaker.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" …
Run Code Online (Sandbox Code Playgroud)

wpf binding user-controls controls

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