我定义了一个类CardTest,继承了UserControl,.cs部分的定义如下:
public partial class Card : UserControl
{
public Card()
{
InitializeComponent();
}
public int W { set; get; }
public int H { set; get; }
}
XAML定义如下:
<UserControl x:Class="CardTest.Card"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="300" Width="300">
<Grid x:Name="GridMain">
<Grid x:Name="GridInside">
</Grid>
</Grid>
</UserControl>我想在XAML部分实现对GridInside的Width和Height针对W和H的绑定。
实现GridInside.Width = W * 2 / 3;
GridInside.Height = H * 2 / 3;
请问在XAML应该怎么写?
非常感谢!
public partial class Card : UserControl
{
public Card()
{
InitializeComponent();
}
public int W { set; get; }
public int H { set; get; }
}
XAML定义如下:
<UserControl x:Class="CardTest.Card"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="300" Width="300">
<Grid x:Name="GridMain">
<Grid x:Name="GridInside">
</Grid>
</Grid>
</UserControl>我想在XAML部分实现对GridInside的Width和Height针对W和H的绑定。
实现GridInside.Width = W * 2 / 3;
GridInside.Height = H * 2 / 3;
请问在XAML应该怎么写?
非常感谢!
解决方案 »
- js刷新问题 求解!!!!
- 记事本程序
- C#属性或方法问题(高分求救)
- 在winForm程序中,一个Form中更新了数据库,需要另一个Form也更新相应界面上的数据,大家一般是怎么来实现的?
- 200分!!!急!!从xml文件中读取被计算的两个数字。要求运用.net中对象的多态性技术实现加、减、乘、除这四个算法。表示层没有限制,wi
- 请教加快GDI+显示,平移,缩放的方法(再发)
- 雪地跪求 C# 如何将CAD图导入WORD中方法!
- 大家帮我解决问题啊!
- 使用filter过滤掉DataTable中字段aa为空值的行怎么做?
- 关于asp.net的问题
- 攒了半年的分都在这了,如果得不到答案,从此就不在上csdn了,来者有份
- 如何写一个抓包工具‘求具体思路
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="300" Width="300" x:Name="control" xmlns:local="clr-namespace:CardTest">
<UserControl.Resources>
<local:Converter1 x:key="converter1"/>
<local:Converter2 x:key="converter2"/>
</UserControl.Resources>
<Grid x:Name="GridMain">
<Grid x:Name="GridInside" Width="{Binding ElementName=control,Path=W,Converter={StaticResource converter1}}" Height="{Binding ElementName=control,Path=H,Converter={StaticResource converter2}}">
</Grid>
</Grid>
</UserControl>