标签: binding

绑定到DataContext中的项目计数

我想绑定到我的DataContext中的Count /项目数量.

我有一个对象,让我说有List<address>一个属性的人.我想显示该人的地址数量,即:5或6或任何情况.

我已经尝试{Binding Path=address#.Count}过其他一些但是看起来似乎没有用.

任何帮助将不胜感激,谢谢.

wpf binding

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

将当前窗口作为CommandParameter传递

如何将当前窗口作为参数传递给命令?

我喜欢在XAML-markup中执行此操作:

<Button Command="CommandGetsCalled" CommandParameter="-this?-" />
Run Code Online (Sandbox Code Playgroud)

wpf binding commandparameter

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

jQuery无法使用.on()将事件绑定到AJAX加载的元素

使用.load,我将以下内容加载到#step_2 div中:

<div id="step_2">
    Select a subcategory:
    <select id="subcategory_id" name="subcategory_id">
        <option value="0">All subcategories</option>
        <option value="68">Cool</option>
        <option value="15">Cooler</option>
        <option value="74">Excellent</option>
    </select>
</div>
Run Code Online (Sandbox Code Playgroud)

然后我试图检测用户选择的东西:

$("#subcategory_id").on("change", function(){
    alert( 'Success!' );
});
Run Code Online (Sandbox Code Playgroud)

但没有成功.有谁看到我做错了什么?非常感谢.

笔记:

这是FireBug看到的完整CSS路径:

html.js body div#container div#main form div#step_2 select#subcategory_id
Run Code Online (Sandbox Code Playgroud)

这是完整的javascript文件,如果上下文很重要:

$(document).ready(function() {

    $("#category_id").change(function() {
        $("#spinner").show();
        $("#step_2").load("process.php?selected=category", { value: $(this).val() }, function() {
            // Do something to say the data has loaded sucessfully
            $("#spinner").hide();
        });
    });

    $("#subcategory_id").on("change", function(){
        alert( 'Success!' );
    });

});
Run Code Online (Sandbox Code Playgroud)

jquery events binding javascript-events

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

WPF绑定到局部变量

你能绑定到这样的局部变量吗?

SystemDataBase.cs

namespace WebWalker
{
    public partial class SystemDataBase : Window
    {
        private string text = "testing";
...
Run Code Online (Sandbox Code Playgroud)

SystemDataBase.xaml

 <TextBox 
       Name="stbSQLConnectionString" 
       Text="{SystemDataBase.text}">
 </TextBox>
Run Code Online (Sandbox Code Playgroud)

??

文本设置为局部变量"text"

data-binding wpf binding

23
推荐指数
3
解决办法
8万
查看次数

Asp.net MVC中的自定义DateTime模型绑定器

我想为DateTime类型编写自己的模型绑定器.首先,我想写一个我可以附加到我的模型属性的新属性,如:

[DateTimeFormat("d.M.yyyy")]
public DateTime Birth { get; set,}
Run Code Online (Sandbox Code Playgroud)

这是简单的部分.但是粘合剂部分有点困难.我想为类型添加一个新的模型绑定器DateTime.我也可以

  • 实现IModelBinder接口并编写我自己的BindModel()方法
  • 继承DefaultModelBinder和覆盖BindModel()方法

我的模型有如上所示的属性(Birth).因此,当模型尝试将请求数据绑定到此属性时,BindModel(controllerContext, bindingContext)将调用我的模型绑定器.一切都好,但是.如何从controller/bindingContext获取属性属性,以正确解析我的日期?我怎样才能到达PropertyDesciptor房产Birth

编辑

由于关注点的分离,我的模型类是在一个没有(也不应该)引用System.Web.MVC程序集的程序集中定义的.设置自定义绑定(类似于Scott Hanselman的示例)属性是禁止的.

asp.net-mvc binding modelbinders custom-model-binder

23
推荐指数
3
解决办法
3万
查看次数

WPF将父绑定对象传递给转换器

我有ItemsControl绑定到Student类型的集合.在ItemTemplate中我有一个TextBox,它使用IValueConverter来做一些自定义计算和逻辑.我想将实际的Student对象传递给值转换器,而不是它的属性.我怎样才能做到这一点?这是我的代码示例.

 <ItemsControl ItemsSource="{Binding StudentList}">
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <TextBlock Text="{Binding Name}" />
                                    <TextBlock Text="{Binding ????, Converter={StaticResource MyConverter}}" />
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
 </ItemsControl>
Run Code Online (Sandbox Code Playgroud)

在代码我有这个

public class MyValueConverter : IValueConverter
{
      public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            // I want 'value' to be of type Student.
            return null;
        }
} 
Run Code Online (Sandbox Code Playgroud)

wpf binding relativesource parent

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

在xaml中绑定后是否可以添加更多字符?

我想知道什么,找不到任何相关的主题.我有以下绑定:

Content="{x:Static resx:Resource.Form_OtherOption_Description}"
Run Code Online (Sandbox Code Playgroud)

这将在标签中放置一个字符串.我问自己的是,如果我可以在绑定之后添加":",而不是在代码中,只需在xaml中添加.标签代表"名称:".但添加":"作为绑定的一部分不是一种选择.

编辑

我在3.5版本工作

有什么建议.

提前致谢.

wpf xaml binding

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

如果底层DataContext为null,如何隐藏控件?

我的视图模型中有一个对象,它有一堆属性,其中一些偶尔会为null.如果这些特定控件为null,我不想只显示一些控件.如果绑定为null,我将如何隐藏控件?我在想某种转换器,但不知道我是怎么做的.有任何想法吗?

编辑:对不起,我应该提一下,这也将在Silverlight中,所以我不确定Style触发器是否会起作用......?

c# silverlight wpf datacontext binding

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

什么是JSF中的组件绑定?何时优先使用?

binding在以下问题中阅读了有关属性的组件绑定:

据我所知,它将视图中JSF标记后面的UI组件绑定到UIComponent辅助bean中的属性.但是,我很困惑组件绑定的用途以及何时应该使用它.有人可以用更简单的方式解释它并给出一些实际的例子吗?

jsf binding components

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

从datatemplate内部绑定到viewmodel

我有多个视频显示它们与Mainviewmodel中的视频选择绑定.一切正常,直到我尝试将enter命令绑定到Mainviewmodel.我不知道这个的语法.目前,绑定设置为Video而不是Mainviewmodel.

错误信息:

'StartVideoCommand' property not found on 'object' ''Video'   
Run Code Online (Sandbox Code Playgroud)

XAML:

<Window.Resources>
  <local:MainViewModel x:Key="MainViewModel"/>
</Window.Resources>
  <Grid DataContext="{StaticResource MainViewModel}">
    <ListBox ItemsSource="{Binding Videos}">
      <ListBox.ItemTemplate>
        <DataTemplate>
          <Grid>
            <Grid.InputBindings>

!!!           <KeyBinding Key="Enter" Command="{Binding StartVideo}" /> !Bound to Video not to Mainviewmodel grrr  

            </Grid.InputBindings>
             ... layout stuff
              <TextBlock Text="{Binding Title}" Grid.Column="0" Grid.Row="0" Foreground="White"/>
              <TextBlock Text="{Binding Date}" Grid.Column="0" Grid.Row="1" Foreground="White" HorizontalAlignment="Left"/>
              <TextBlock Text="{Binding Length}" Grid.Column="1" Grid.Row="1" Foreground="White" HorizontalAlignment="Right"/>
             ... closing tags
Run Code Online (Sandbox Code Playgroud)

wpf binding datatemplate itemtemplate viewmodel

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