Question

GridSplitterControl.xaml

<sdk:GridSplitter x:Class="JustLogIt.Common.GridSplitterControl"
                  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                  xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                  xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
                  xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
                  mc:Ignorable="d">
    <sdk:GridSplitter.Template>
        <ControlTemplate TargetType="sdk:GridSplitter">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="auto" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="auto" />
                </Grid.ColumnDefinitions>
                <telerik:RadButton Grid.Row="0"
                                   Width="10"
                                   Height="20"
                                   HorizontalAlignment="Center"
                                   Click="Click"
                                   Cursor="Hand" />
                <Border Grid.Row="1"
                        BorderBrush="LightGray"
                        BorderThickness="5" />
            </Grid>
        </ControlTemplate>
    </sdk:GridSplitter.Template>
</sdk:GridSplitter>

GridSplitterControl.xaml.cs

    public partial class GridSplitterControl : GridSplitter
    {
        GridLength AutoSize = new GridLength(1.0, GridUnitType.Auto);
        GridLength ZeroSize = new GridLength(0.0);
        public ColumnDefinition Left{ set; get;}
        public GridSplitterControl()
        {
            InitializeComponent();

        }
        public GridSplitterControl(ColumnDefinition ColLeft)
        {
            InitializeComponent();
            Left = ColLeft;
        }
        public void Click(object sender, RoutedEventArgs e)
        {
            if (Left != null)
            {
                Left.MinWidth = 10.0;
                if ((Left.Width.Value + 10) == Left.MinWidth)
                    Left.Width = AutoSize;
                else if (Left.Width.Value != AutoSize.Value)
                    Left.Width = AutoSize;
                else Left.Width = ZeroSize;
            }
            //ClickNotify(sender, e);
        }

        public event EventHandler ClickCompleted;
        private void ClickNotify(object senderAIF, RoutedEventArgs eAIF)
        {
            if (ClickCompleted != null)
                ClickCompleted(senderAIF, eAIF);
        }
    }
  1. The Click event can work, but I have no idea to set the Left(ColumnDefinition) in xaml file which used this Element.
    <Grid x:Name="LayoutRoot1"
                  Grid.Row="1"
                  Margin="5"
                  Background="White">
         <Grid.ColumnDefinitions>
              <ColumnDefinition x:Name="LvCol_10" Width="*" />
              <ColumnDefinition x:Name="LvCol_11" Width="*" />
         </Grid.ColumnDefinitions>
         <Mylayout:GridSplitterControl x:Name="GridSplitter_Left"
                                       Grid.RowSpan="7"
                                       Grid.Column="0"
                                       Width="10"
                                       VerticalAlignment="Stretch"
                                       IsEnabled="True"
                                       Left=? /> < !-- How to set "LvCol_11" in here? -->
    </Grid>`
Était-ce utile?

La solution

It seems like that you want to set the grid.row as property which is used when the button click.

Maybe you can try this...

GridSplitterControl.xaml.cs

private void UI_Loaded(object sender, RoutedEventArgs e)
{
    if (sender is GridSplitter)
    {
        Grid ParentGrid = this.ParentOfType<Grid>();
        SetLocation(ParentGrid);
    }
}
public void SetLocation(Grid p_Layout)
{
    int index = Grid.GetColumn(this);
    ColumnDefinition ColLocation = p_Layout.ColumnDefinitions[index];
    ColLocation.MinWidth = 10;
    Left = ColLocation;
}

Becarefully, besure your element's parent(Up one level) is grid.

If parent is stackPanel, border, or rectangle, it will be not working, maybe.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top