WP8.1 C#代码 添加/获取Grid.ColumnDefinitions/RowDefinitions

WP8.1:

ColumnDefinitions和RowDefinitions的道理是相同的,语法顺序是一样的,只不过是将ColumnDefinitions换成RowDefinitions而已

获取并且重新设置

 var the_grid_CD = This_Gird.ColumnDefinitions; //获取控件的ColumnDefinitions列表
  var the_get_CD=the_grid_CD.First(i=>i.Width==newGridLength(8,GridUnitType.Star));//使用First语法获取到你想要的CD
 the_get_CD.Width =newGridLength(15,GridUnitType.Star);//重新设置值
  //the_grid_CD.ElementAt(索引) 也可以用ElementAt语法获取其ColumnDefinitions

添加

             ColumnDefinition SetCD = new ColumnDefinition(); //新建一个ColumnDefinition
             SetCD.Width = new GridLength(8, GridUnitType.Star);//第一个参数,是大小,第二个参数是类型
             The_Grid.ColumnDefinitions.Add(SetCD);//添加到ColumnDefinition中,位于列表最后一个
//the_grid_CD.Insert(索引,新建ColumnDefinition) 也可以使用这个方法添加到指定的位置

 

转载于:https://www.cnblogs.com/T-ARF/p/5894040.html

<ItemsControl x:Class="HDSProject.Control.CustomFont" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:HDSProject.Control" mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="800" x:Name="itemCtrl" ItemsSource="{Binding Path=Title2, RelativeSource={RelativeSource Mode=Self}}" FontSize="20" Foreground="Teal" > <ItemsControl.ItemContainerStyle> <Style TargetType="ContentPresenter"> <Setter Property="VerticalAlignment" Value="Center" /> </Style> </ItemsControl.ItemContainerStyle> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <StackPanel Orientation="Horizontal" HorizontalAlignment="Center"/> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemTemplate> <DataTemplate> <StackPanel> <Border Margin="{Binding Path=CharacterSpacing, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:CustomFont}}"> <TextBlock Text="{Binding}" /> </Border> <Rectangle Height="1" Fill="{Binding Foreground, ElementName=itemCtrl}" Margin="0,0,0,5"> <Rectangle.Style> <Style TargetType="Rectangle"> <Setter Property="Visibility" Value="Collapsed" /> <Style.Triggers> <DataTrigger Binding="{Binding ShowUnderline, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:CustomFont}}" Value="True"> <Setter Property="Visibility" Value="Visible" /> </DataTrigger> </Style.Triggers> </Style> </Rectangle.Style> </Rectangle> </StackPanel> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl>给这个控件添加一个拖动边框改变大小的事件
06-07
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值