gpt4 book ai didi

c# - 如何获取 LightSwitch 中 IContentItemProxy 上的 SetBinding 方法的路径?

转载 作者:太空狗 更新时间:2023-10-29 23:39:23 26 4
gpt4 key购买 nike

我正在尝试创建绑定(bind)以根据所选项目的属性更改标签的背景颜色。我正在使用表格:

this.FindControl("ItemDisplayTitle")
.SetBinding(TextBox.BackgrounProperty, **PATH**,
new MyIconverter(), BindingMode.OneWay);

如果我使用“Value”作为路径,它会使用 ItemDisplayTitle 的值来使用 MyIconverter() 设置颜色

但我真的想使用屏幕上的另一个属性“Health”,但它是此窗口的本地属性。

研究表明我应该 use the form "Details.Entity.AnotherProperty "2012 年 6 月 6 日上午 10:16 - Otis Ranger

但是当我尝试使用“DataSourceName.MyEntityName.MyProperty”时,它似乎不起作用。我也试过“Details.MyEntityName.MyProperty”并在绝望中“Details.Entity.MyProperty”

我很确定我只是精神出了问题,但是应该怎么办DetailsEntityAnotherProperty 是什么?我是否缺少一个明显的引用页面来说明路径应该是什么?

最佳答案

问题是您应该为数据网格上的每一行 添加一个处理程序。它们是 3 个简单的步骤。

拳头结果,注意你可以绑定(bind)所有行或行中的单个控件:

enter image description here

  • 第 1 步。声明转换器。我假设您的转换器运行良好。

这是我的转换器:

Public Class BooleanDateConverter

Implements System.Windows.Data.IValueConverter

Public Function Convert(ByVal value As Object,
ByVal targetType As System.Type,
ByVal parameter As Object,
ByVal culture As System.Globalization.CultureInfo) _
As Object Implements System.Windows.Data.IValueConverter.Convert


If DirectCast(value, Boolean) Then
Return New System.Windows.Media.SolidColorBrush(
System.Windows.Media.Color.FromArgb(170, 102, 255, 245))
Else
Return New System.Windows.Media.SolidColorBrush(
System.Windows.Media.Color.FromArgb(170, 255, 0, 0))
End If

End Function

Public Function ConvertBack(ByVal value As Object,
ByVal targetType As System.Type,
ByVal parameter As Object,
ByVal culture As System.Globalization.CultureInfo) _
As Object Implements System.Windows.Data.IValueConverter.ConvertBack

Return Nothing
End Function

End Class
  • 第 2 步和第 3 步。绑定(bind)数据网格和数据网格行:

在 InitializeDataWorkspace 上绑定(bind)数据网格:

    Private Sub Conversio_CategoriaPDI_a_ElementDeCosts_InitializeDataWorkspace(
saveChangesTo As System.Collections.Generic.List(
Of Microsoft.LightSwitch.IDataService))

AddHandler Me.FindControl(
"TConversio_CategoriaPDI_a_ElementDeCosts"
).ControlAvailable, AddressOf bindejarDataGrid

End Sub

这是数据网格的处理程序。绑定(bind)到函数内部的每一行:

    Private Sub bindejarDataGrid(
sender As Object,
e As Microsoft.LightSwitch.Presentation.ControlAvailableEventArgs)

AddHandler DirectCast(e.Control, Windows.Controls.DataGrid
).LoadingRow, AddressOf bindejar
End Sub

为每一行绑定(bind)一些控制行:

    Private Sub bindejar(sender As Object, 
e As Windows.Controls.DataGridRowEventArgs)
Dim b As Windows.Data.Binding = New Windows.Data.Binding("parametritzat")
b.Mode = Windows.Data.BindingMode.OneTime
b.Converter = New BooleanDateConverter
b.ValidatesOnExceptions = True
e.Row.SetBinding(System.Windows.Controls.Label.BackgroundProperty, b)

End Sub

感谢:

关于c# - 如何获取 LightSwitch 中 IContentItemProxy 上的 SetBinding 方法的路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19055178/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com