【问题标题】:XAML Binding of related objects相关对象的 XAML 绑定
【发布时间】:2015-09-04 15:26:41
【问题描述】:

我有 2 节这样的课

class X {

    int IdOfX;
    string NameX;
    string etcX;

    int IdOfY;
}

class Y{

    int IdOfY;
    string NameY;
    string etcY;

    int IdofX;
}

这些类现在正在简化我在项目中的类...我不能使用 X 类类型的变量,因为这些类必须序列化为 json 和 imao 这将导致麻烦,因为 X 类有一个成员 Y 和Y 类有一个成员 X,所以这将在一个循环中结束......

public List<X> xs { get; set; } = new List<X>();
public List<Y> ys { get; set; } = new List<Y>();

还有一个像这样的xaml

<Grid>
  <ListView Name="lstView">
    <ListView.View>
      <GridView>
        <GridView.Columns>
          <GridViewColumn Header="NameX" Width="100" 
                          DisplayMemberBinding="{Binding Path=NameX}" />

          <GridViewColumn Header="NameY" Width="80" 
                          DisplayMemberBinding="{Binding Path=???}" />

        </GridView.Columns>
      </GridView>
    </ListView.View>
  </ListView>    
</Grid>

如何显示通过 id 连接到我的类 X 的 Y 的名称?

提前致谢

【问题讨论】:

    标签: c# .net xaml


    【解决方案1】:

    使用视图模型。例如:

    public class xViewModel : x
    {
        public string NameY { get; set; }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-11
      • 1970-01-01
      • 1970-01-01
      • 2012-02-06
      • 2011-02-28
      • 2013-05-03
      • 2015-03-25
      • 1970-01-01
      相关资源
      最近更新 更多