标签: binding

在C#中设置TabControl的DisplayMemberPath

我用C#代码创建了一个TabControl.我将其ItemsSource绑定到一个集合并设置边距.出于某种原因,设置其DisplayMemberPath不会工作.

_tabControl = new TabControl();
_tabControl.Margin = new Thickness(5);
_tabControl.DisplayMemberPath = "Header";
_tabControl.SetBinding(ItemsControl.ItemsSourceProperty, itemsSourceBinding);
Run Code Online (Sandbox Code Playgroud)

集合中的每个项目都有一个名为"Header"的属性.

为什么这不起作用?

安德烈

编辑:这是所有相关的代码:

public partial class VariationGroupPreviewOptionsView
{
    public string Header { get; set; }

    public VariationGroupPreviewOptionsView()
    {
        InitializeComponent();
        DataContext = new VariationGroupPreviewOptionsViewModel();
    }
}

private void OptionsCommandExecute()
{
    var dlg = new OptionsDialog();
    dlg.ItemsSource = new List<ContentControl>() {new VariationGroupPreviewOptionsView(){Header = "Test"}};
    dlg.ShowDialog();
}

public class OptionsDialog : Dialog
{

    public static readonly DependencyProperty ItemsSourceProperty =
        DependencyProperty.Register("ItemsSource", typeof (IEnumerable), typeof (OptionsDialog), new PropertyMetadata(default(IEnumerable)));

    public IEnumerable …
Run Code Online (Sandbox Code Playgroud)

c# wpf binding tabcontrol

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

WPF无法从变量更新文本框

使用WPF和VB.net,我想用当前日期和时间更新文本块中的文本框.我使用计时器,它似乎正在触发,并将对象属性设置为"现在".我正在使用iNotifyPropertyChanged.

我得到的只是一个没有数据的空文本框.你能帮我吗?也许我的背景是关闭的?

XAML

<Window x:Class="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">
<Grid>
    <TextBlock DataContext="oTime"> 
        <TextBox x:Name="myTextBox" 
                 Width="200" Height="50" Foreground="Black" 
                 Text="{Binding Path=oTime.TimeUpdate}"></TextBox>
    </TextBlock>
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)

VB代码

Imports System.ComponentModel
Imports System.Windows.Threading

Class MainWindow
  Public oTime As TimeUpdate = New TimeUpdate
  Private dpTimer As DispatcherTimer

  Private Sub TextBlock_SourceUpdated(ByVal sender As System.Object, ByVal e As System.Windows.Data.DataTransferEventArgs)

  End Sub

  Private Sub MainWindow_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
      dpTimer = New DispatcherTimer
      dpTimer.Interval = TimeSpan.FromMilliseconds(1000)
      AddHandler dpTimer.Tick, AddressOf TickMe
      dpTimer.Start()
  End Sub

  Private …
Run Code Online (Sandbox Code Playgroud)

vb.net wpf binding inotifypropertychanged

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

ComboBox ItemTemplate不支持"Image"类型的值

我正在尝试将WPF组合框绑定到可观察的图像集合.这是我的收藏:

    public class AvatarPhoto
    {
        public int AvatarId { get; set; }
        public BitmapImage AvatarImage { get; set; }
    }
    public ObservableCollection<AvatarPhoto> AvailableProfilePictures { get; private set; }
Run Code Online (Sandbox Code Playgroud)

这是我的xaml: 在此输入图像描述

Visual Studio给出了这个编译时错误:属性'ItemTemplate'不支持'Image'类型的值.

为什么会出现这个错误?

谢谢

更新:谢谢你的回答!它解决了这个问题.

现在我已经更新了我的代码但是我在ComboBox中看到了这个: 在此输入图像描述

为什么不能正确显示图片?在调试窗口中,我可以看到我的集合已正确填充:

在此输入图像描述

wpf binding combobox image itemtemplate

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

如何获取SetBinding方法

我需要做这样的事情:http: //social.msdn.microsoft.com/Forums/en-US/wpf/thread/982e2fcf-780f-4f1c-9730-cedcd4e24320/

我决定按照约翰史密斯建议的最佳方式.

我试图在xaml中设置绑定,它不起作用(目标始终为null).

我决定在代码中手动设置绑定(用于调试目的),因此我需要执行DateRange对象的"SetBinding"方法.

DateRange类型的对象中不存在此方法.

有任何想法吗?

<TextBox Grid.Row="1"
         Grid.Column="1"
         Name="Xml_Name"
         >
    <TextBox.Text>
        <Binding XPath="@name" UpdateSourceTrigger="PropertyChanged" >
            <Binding.ValidationRules>
                <local:UniqueValidationRule x:Name="uniqueDatasourcesRule001" >
                    <local:UniqueValidationRule.UniqueCollection>
                        <local:UniqueDependencyObject uu="{Binding  ElementName=Xml_Name, Path=Name, UpdateSourceTrigger=PropertyChanged}" />
                    </local:UniqueValidationRule.UniqueCollection>
                </local:UniqueValidationRule>
            </Binding.ValidationRules>
        </Binding>
    </TextBox.Text>
</TextBox>



public class UniqueDependencyObject : DependencyObject
{
    public static readonly DependencyProperty uu11Property =
        DependencyProperty.Register("uu", typeof(string), typeof(UniqueDependencyObject));

    public string uu
    {
        set { 
            SetValue(uu11Property, value); }
        get { 
            return (string)GetValue(uu11Property); }
    }



}

public class UniqueValidationRule : ValidationRule
{
    public UniqueDependencyObject UniqueCollection
    {
        get;
        set;
    } …
Run Code Online (Sandbox Code Playgroud)

c# wpf xaml binding

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

在我的usercontrol和ViewModel之间绑定

不能做绑定

随机(MyViewModel) - > VMTestValue(MyViewModel) - > TestUserControl(MainWindow)

"MyViewModel"是"MainWindow"的ViewModel

所有项目:http://rusfolder.com/32608140

TestUserControl.xaml

<UserControl x:Class="TestBinding.TestUserControl"
             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" 
             Background="Green"
             d:DesignHeight="300" d:DesignWidth="300">
    <Grid>
        <TextBlock Background="Gray" Margin="50" FontSize="18" Text="{Binding TestValue}" />
        <Rectangle  Height="200" Width="{Binding TestValue}" Fill="#FFFF1717" />
    </Grid>
 </UserControl>
Run Code Online (Sandbox Code Playgroud)

TestUserControl.cs

...
public TestUserControl()
        {
            InitializeComponent();

            this.DataContext = this;
        }

        public static readonly DependencyProperty TestValueProperty =
           DependencyProperty.Register("TestValue", typeof(int), typeof(TestUserControl),
               new FrameworkPropertyMetadata((int)255)
               );

        public int TestValue
        {
            set { SetValue(TestValueProperty, value); }
            get
            {
                return (int)GetValue(TestValueProperty);
            }
        }
...
Run Code Online (Sandbox Code Playgroud)

MyViewModel.cs

using …
Run Code Online (Sandbox Code Playgroud)

binding dependencies prism properties mvvm

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

淘汰赛风格绑定不工作ie8

我正在使用Knockout.js,我有以下绑定来添加间距(margin-left).

<div class="editor-field" data-bind="style : { 'margin-left' : ($root.getHierarchyLevel($index()) * 30 + 'px')}">
Run Code Online (Sandbox Code Playgroud)

这适用于IE9和IE8兼容模式.但是当我在Windows XP上运行IE8中的相同代码时,我看不到任何间距.

我创建了一个jsfiddle示例.这在IE9中在blah之前添加间距,但在IE8中没有.

有任何想法吗??

binding styles internet-explorer-8 knockout.js

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

WPF MVVM绑定错误

我正在使用MVVM模式.在我的ViewModel中,我有一个公共的ObservableCollection:

public ObservableCollection<SettingsTemplateHistoryItemViewModel> HistoryItemCollection;

public SettingsTemplateViewModel()
    {
        this.HistoryItemCollection = new ObservableCollection<SettingsTemplateHistoryItemViewModel>();
    }
Run Code Online (Sandbox Code Playgroud)

在我的视图中,我有一个ItemsControl,其ItemsSource属性绑定到ViewModel中的ObservableCollection.

<ItemsControl ItemsSource="{Binding HistoryItemCollection}"/>
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

BindingExpression path error: 'HistoryItemCollection' property not found on 'object' ''SettingsTemplateViewModel' (HashCode=48413709)'. BindingExpression:Path=HistoryItemCollection; DataItem='SettingsTemplateViewModel' (HashCode=48413709); target element is 'ItemsControl' (Name=''); target property is 'ItemsSource' (type 'IEnumerable')
Run Code Online (Sandbox Code Playgroud)

我很困惑.我100%确定该属性存在于View的DataContext(即ViewModel)中.我已将属性名称复制并粘贴到View中,因此绑定路径必须正确.View和ViewModel通过隐式/类型化DataTemplates连接起来.我错过了什么?

wpf binding mvvm

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

R中的列绑定

我在R中使用cbind命令将许多data.frames绑定在一起,并且每个数据框具有相同的列名,因此当我将它们全部绑定时,R会自动更改列名与其原始名称.例如,有一个名为"X"的列,所以对于每个绑定,它重命名这个X.1,X.2,X.3等.有没有办法让我绑定它们而不改变任何列名并有多个具有相同名称的列?

我希望这样做的原因是我可以按照列名称对组合后的data.frame进行排序,以便按照它们在组合data.frame中的相同顺序将所有相等的命名列组合在一起.

binding r dataframe

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

Knockout Jquery绑定点击不起作用

第一个问题!希望我做得好.

我有这个绑定列表:

<table id="restaurants_list" data-bind="foreach : restaurants" style="display: none">
    <tr>
        <td data-bind="text:name"></td>
        <td data-bind="text:address.address1"></td>
        <td data-bind="text:address.address2"></td>
        <td data-bind="text:address.postcode + ' ' + address.suburb"></td>
        <td>
            <input type="button" value="show" data-bind="click: $root.showmap" />
        </td>
    </tr>
</table>
<div id="map"></div>
Run Code Online (Sandbox Code Playgroud)

这里的模型视图:

function RestaurantsViewModel() {
    var self = this;
    self.restaurants = data;
    self.showMap = function (restaurant) {
        $("#map").show();
        ....
    };
    showMap(restaurants[0]);
};
Run Code Online (Sandbox Code Playgroud)

最后绑定:

$(document).ready(function () {
    $("#link_get_restaurants").bind("click", get_restaurants);
});
function get_restaurants(event) {
    $("#restaurants_list").show();
    ko.applyBindings(new RestaurantsViewModel());
}
Run Code Online (Sandbox Code Playgroud)

第一个showmap(restaurants[0])工作正常.但是,click : $root.showmap不开火.

我做错了什么?我也使用Jquery,我不知道它是否可以来自那个.

谢谢.

jquery binding click knockout.js

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

根据枚举值启用TextBox

我有我想启用如果一个TextBox Order的状态会显示为OrderStatus.NewOrderStatus.Ordered.它是另一回事,TextBox应该保持禁用状态.

<TextBox Text="{Binding OrderedAmount}" IsEnabled="True"/>
Run Code Online (Sandbox Code Playgroud)

我假设我需要使用某种MultiBinding,但似乎无法在这种特殊情况下找到合适的资源.

wpf enums binding

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