标签: binding

DataGridComboBoxColumn ItemSource绑定不起作用

在来自Resources的DataGridComboBoxColumn ItemSource的所有示例中.难道不能直接绑定到CodeBehind中的列表吗?

wpf binding

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

为什么我不能绑定到WPF中的类上的字段而不是绑定到属性

似乎在WPF中我不能绑定到对象的公共字段,而只能绑定到公共属性.这是WPF的故意设计决定,还是我只是弄错了语法?

这是一个示例代码段:

public class User
{
  public string Username;
  public string FullName;
  public string DisplayName
  {
    get { return FullName; }
  }
}
Run Code Online (Sandbox Code Playgroud)

WPF片段:

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="User Tool" >
  <Window.Resources>
    <DataTemplate x:Key="UserTemplate">
      <TextBlock Text="{Binding Path=DisplayName}" />
    </DataTemplate>
  </Window.Resources>
  <ListBox Name="listBoxUsers" ItemTemplate="{StaticResource UserTemplate}" ItemsSource="..." />
</Window>
Run Code Online (Sandbox Code Playgroud)

如果我将绑定路径更改为用户名或全名,则屏幕上不会显示任何内容.是否有替代语法绑定到字段,或仅绑定属性?

.net c# wpf binding

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

如何将csharp绑定变量传递给Javascript函数

我想将c#绑定变量传递给javascript函数.这是我的代码:

<asp:LinkButton ID="lbID" runat="server" Text="<%#Text%>" OnClientClick="passAccessory('<%#Bind(variable)%>'); "></asp:LinkButton>
Run Code Online (Sandbox Code Playgroud)

但它总是会产生错误:"htmlfile:未实现".

并且代码没有被解释 onclick="passAccessory('&lt;%#Bind(variable)%>');"

有谁知道如何解决它?

谢谢.

编辑:我已将代码更改为

<asp:LinkButton ID="lbID" runat="server" Text="<%#Text%>" OnClientClick="passAccessory('<%# Eval("lblTest.ClientID") %>');"></asp:LinkButton>
Run Code Online (Sandbox Code Playgroud)

这是它与之相关的代码,它使用了 lblTest.ClientID

<asp:Label ID="lblTest" runat="server" Text='<%#Bind("reference")%>' />

但我收到一个错误:HttpException. Databinding ... does not contain a property with the name lblTest.我的代码有什么问题吗?

编辑: 这些帖子给了我一个线索.

http://www.west-wind.com/Weblog/posts/5364.aspx

我试图学习如何将IEnumerable LINQ集合绑定到转发器

现在我想用

<asp:LinkButton ID="lbTest" runat="server" Text='<%#Text%>' OnClientClick='<%#string.Format("passAccessory(\"{0}\");", Eval("Ref"))%>'></asp:LinkButton>
Run Code Online (Sandbox Code Playgroud)

javascript c# variables binding function

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

如果文本字符串值等于零,如何隐藏texblock?

如果动态生成的值等于零,我想让texblock不可见.我认为可以使用DataTrigger单独在XAML中完成.我想知道是否有人可以帮助找到适当的解决方案.先感谢您.

wpf binding wpf-controls

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

如何从转换器中引用xaml模板?

我目前停留在通过转换器为控件分配不同模板的问题上.

所以我有2个模板.

        <ControlTemplate x:Name="_templateA" x:Key="templateA">
            <StackPanel Grid.Column="0" Margin="0,0,5,0">
                <Blah />
            </StackPanel>
        </ControlTemplate>

        <ControlTemplate x:Name="_templateB" x:Key="templateB">
            <StackPanel Grid.Column="0" Margin="0,0,5,0">
                <Blah Blah />
            </StackPanel>
        </ControlTemplate>
Run Code Online (Sandbox Code Playgroud)

我使用这个转换器控制这个:

<ControlA x:Name="_controlA" >
     <Control Template="{Binding Converter={StaticResource templateConverters}}" />
</ControlA>
Run Code Online (Sandbox Code Playgroud)

我的转换器:

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        Object a;
        ControlTemplate template = null;

        try
        {
            a= value as ObjectA;
            if (value != null)
                template = a.useTemplate1 ? [templateA from xaml] : [templateB from xaml];
        }
        catch (Exception ex)
        {
            Debug.Assert(false, ex.ToString());
        } …
Run Code Online (Sandbox Code Playgroud)

wpf binding converter datatemplate controltemplate

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

使用ValueConverter的WPF网格IsEnabled

我有一个带有Grid和TreeView的WPF窗口.Grid的datacontext绑定到树视图上的选定项.但是,因为并非所有treeviewitems都适用,所以如果treviewitem不适用,我想禁用网格.所以,我创建了一个值转换器来进行空检查并返回一个bool.(在这种情况下,适用的项目不会为空)

问题是从未使用过值转换器.我设定了破发点,他们从未被击中过.我有其他价值转换器我正在使用它们都工作得很好.

有什么我想念的吗?

<Grid Grid.Column="1" Grid.Row="0" DataContext="{Binding MyVal}" IsEnabled="{Binding MyVal, Converter={StaticResource NullCheckConverter}}" Margin="2,2,2,2">
Run Code Online (Sandbox Code Playgroud)

并不是说这个问题很重要,但这里是ValueConverter代码:

internal class NullCheckValueConverter : IValueConverter
{
    #region IValueConverter Members

    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        return !(value == null);
    }

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new NotImplementedException();
    }

    #endregion
}
Run Code Online (Sandbox Code Playgroud)

c# wpf binding ivalueconverter isenabled

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

WPF:如何绑定到name属性

我可以绑定到name属性吗?这似乎不起作用:

<TextBlock Name="FordPerfect" Text="{Binding Path=Name, Mode=OneWay}"/>
Run Code Online (Sandbox Code Playgroud)

难道我做错了什么?

编辑:
添加ElementName=FordPerfect"解决了问题.我不明白的是为什么只有绑定到Name需要这个,而其他属性没有.

注意:将第二个(设计)问题移到另一个问题(我应该在第一次放置......)

谢谢

wpf binding

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

将ListBox绑定到Dictionary <int,string>

我想将Silverlight ListBox绑定到Dictionary<int, string>.我试过以下没有成功:

someListBox.ItemsSource = someItems;
Run Code Online (Sandbox Code Playgroud)

someListBox.ItemsSource = someItems.Values;
Run Code Online (Sandbox Code Playgroud)

silverlight binding listbox silverlight-4.0

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

基于父级属性的WPF样式项

我有一个带属性的视图模型

IEnumerable<Page> Pages { get; }
Page CurrentPage { get; }
Run Code Online (Sandbox Code Playgroud)

我有像这样的XAML绑定:

<ItemsControl ItemsSource="{Binding Pages}" Margin="10">
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <BulletDecorator>
                <BulletDecorator.Bullet>
                    <TextBlock Text=" •  " FontWeight="Heavy" />
                </BulletDecorator.Bullet>

                <TextBlock Text="{Binding Title}" FontWeight="{Binding ????, Converter={StaticResource BTFWC}}" />
            </BulletDecorator>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>
Run Code Online (Sandbox Code Playgroud)

视图模型具有属性PagesCurrentPage.我希望只要在视图模型上设置该页面,列表中页面的文本就是粗体CurrentPage.我该怎么做才能代替"????" 在XAML上面实现那个目的?我想避免在页面上有"IsCurrent"属性,因为我觉得知道它是否是当前页面并不是它的责任.

PS:BTFWC是一个"布尔到字体重量转换器",如果你想知道的话.

.net wpf binding

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

如何将活动TabItem的名称绑定到WPF中的Label?

实际标签显示控件的命名空间,而不是活动tabitem的名称(标题).

..
<Label Content="{x:Type TabControl}" />
</Grid>

<TabControl>

    <TabItem Header="Header1" />
    <TabItem Header="Header2" />
    ..
Run Code Online (Sandbox Code Playgroud)

wpf binding tabcontrol tabitem

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