Click here to Skip to main content
16,020,257 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I am creating a Windows 8.1 app using https://slideview.codeplex.com in the Windows 10 with help of Visual Studio 2015.

I have added grid to the design with 1 row and two column. In the first page there is big image and no text and in other pages there is icon and text. So I am putting if 4* in first column for first page and 2* in first for second page all works good but I wanted to make it dynamic in ContentPresenter and then I can assign it from C#.

Kindly somebody help me.

I tried in different way like I put below code in SlideApplicationFrame.cs

C#
#region FirstColumnWidth (DependencyProperty)

    /// <summary>
    /// header Image First Column Width
    /// </summary>
    public GridLength FirstColumnWidth
    {
        get { return (GridLength)GetValue(FirstColumnWidthProperty); }
        set { SetValue(FirstColumnWidthProperty, value); }
    }
    public static readonly DependencyProperty FirstColumnWidthProperty =
            DependencyProperty.Register("FirstColumnWidth", typeof(GridLength), typeof(SlideApplicationFrame),
                new PropertyMetadata(new GridLength(4, GridUnitType.Star))); 

    #endregion

    #region ContentFirstColumnWidth (Attached DependencyProperty)

    public static readonly DependencyProperty ContentFirstColumnWidth =
            DependencyProperty.RegisterAttached("ContentFirstColumnWidth", typeof(GridLength), typeof(SlideApplicationFrame), new PropertyMetadata(new GridLength(4, GridUnitType.Star)));

    public static void SetContentFirstColumnWidth(DependencyObject o, GridLength value)
    {
        o.SetValue(ContentFirstColumnWidth, value);
    }

    public static GridLength GetContentFirstColumnWidth(DependencyObject o)
    {
        return (GridLength)o.GetValue(ContentFirstColumnWidth);
    }

    #endregion

Then I use it in my ContentPresenter Like this

XML
<ContentPresenter  library:SlideApplicationFrame.ContentFirstColumnWidth="{TemplateBinding FirstColumnWidth}" Grid.Column="1"/>

and at the end in style setter

XML
<ColumnDefinition Width="{Binding library:SlideApplicationFrame.ContentFirstColumnWidth}"/>

Whole Style Setter is as below

XML
<Setter Property="HeaderTemplate">
            <Setter.Value>
                <DataTemplate>
                    <Grid  x:Name="GridHeader">
                        <Grid.RowDefinitions>
                            <RowDefinition/>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="{Binding library:SlideApplicationFrame.ContentFirstColumnWidth}"/>
                            <ColumnDefinition Width="5*"/>
                        </Grid.ColumnDefinitions>
                    </Grid>
                </DataTemplate>
            </Setter.Value>
        </Setter>

and setting from MainPage.xaml.cs

C#
SlideApplicationFrame RootFrame = Window.Current.Content as SlideApplicationFrame;

RootFrame.FirstColumnWidth = new GridLength(4, GridUnitType.Star);

Please help me I will be highly appreciated
Posted
Comments
Irina Pykhova 9-Nov-15 13:56pm    
and what is the problem? From your snippets I have only one suggestion, to replace TemplateBinding by simple Binding with RelativeSource TemplatedParent. TemplateBinding might work not for all properties. But I didn't see full code and xaml, and you didn't tell what exactly doesn't work, so it is just a guess

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900