WINUI 后台代码绑定

发布时间 2023-07-21 10:57:27作者: 盛沧海

以image为例

 

前端进行绑定时哪下,注意下述代码中用的是x:Bind,用它进行绑定时需要标明其绑定ViewModel的key值;用Bingding时则不需要。

 <Image
     x:Name="CTCoronalCImage"
     Width="1010"
     Height="442"
     HorizontalAlignment="Stretch"
     VerticalAlignment="Stretch"
     Source="{x:Bind ViewModel.ctCoronalViewInfo.Source, Mode=TwoWay}" />

 

上述xaml绑定代码在后台代码中则如下:

 CTAxialImage.SetBinding(Image.SourceProperty, new Binding()
 {
     Path = new PropertyPath("Source"),
     Mode = BindingMode.TwoWay,
     Source = ViewModel.ctAxialViewInfo
 });

 

后台 代码进行绑定,主要是为了image进行数据源的切换,以展示3D模型的不同视图……当然你也可能会有其他需求。