This is a migrated thread and some comments may be shown as answers.

Maximise from code behind not working!

3 Answers 127 Views
TileView
This is a migrated thread and some comments may be shown as answers.
Joe Bohen
Top achievements
Rank 1
Joe Bohen asked on 25 Feb 2012, 09:37 AM
Sorry posted this twice!!
Hi,
I have a radtileview with a small number of tiles and I am attempting to loop through the tiles and maximse each one in turn form code behind. I get the  'Object reference not set to an instance of an object.' error when maximise is called. Can you put me right with this.
Regards,
Joe

The Code:

 

For I As Integer = 0 To Me.RadTileView1.Items.Count - 1

Dim item As RadTileViewItem = TryCast(Me.RadTileView1.Items(6), RadTileViewItem)

item.TileState =

 

TileViewItemState.Maximized

Thread.Sleep(5000)

Next


3 Answers, 1 is accepted

Sort by
0
Kiril Stanoev
Telerik team
answered on 27 Feb 2012, 02:51 PM
Hi Joe,

I am not really sure what are you trying to achieve with the described functionality. However, I don't this the usage of Thread is very wise since it blocks the whole UI thread and the application will freeze. What you can try and do is the following:

C#
private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
{
    DispatcherTimer timer = new DispatcherTimer();
    timer.Interval = TimeSpan.FromSeconds(1);
    int index = 0;
    timer.Tick += (o, args) =>
    {
        RadTileViewItem container = this.tileView1.Items[index] as RadTileViewItem;
        container.TileState = TileViewItemState.Maximized;
        index++;
        if (index == this.viewModel.ItemsSource.Count)
        {
            timer.Stop();
        }
    };
    timer.Start();
}

VB

Private Sub Button_Click(sender As Object, e As System.Windows.RoutedEventArgs)
    Dim timer As New DispatcherTimer()
    timer.Interval = TimeSpan.FromSeconds(1)
    Dim index As Integer = 0
    timer.Tick += Function(o, args) Do
        Dim container As RadTileViewItem = TryCast(Me.tileView1.Items(index), RadTileViewItem)
        container.TileState = TileViewItemState.Maximized
        index += 1
        If index = Me.viewModel.ItemsSource.Count Then
            timer.[Stop]()
        End If
    End Function
    timer.Start()
End Sub

Give it a try and let me know if it helps. I'd be glad to further assist you.

Kind regards,
Kiril Stanoev
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Joe Bohen
Top achievements
Rank 1
answered on 28 Feb 2012, 12:41 PM

Hi Kiril

Thanks for your reply I am afraid my question was not very clear the tileview is being used as a type of rotating dashboard with no user interaction once the application has loaded. The code snippet is part of a sub which is called on a timer event the sub runs and each tile meeting the criteria is displayed and the timer is re-set to run in five minutes time.  

I have used the RadFluidContentControl example with a viewmodel as the basis for my project and this works well I have also changed the method of maximising the tiles to use the binding methos as suggested in your recent sample given to Xiver on Feb 8, but I think the fluid content template prevents  the desired functionality the tile is successfully maximised but immediately bounces back to all tiles being restored.  I am would appreciate it if you could take a look at the xaml and see if you can spot the problem.

 

 

Regards,

Joe

 

The xaml looks like this:

 

<Page x:Class="Page1"

      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:telerik=http://schemas.telerik.com/2008/xaml/presentation

             xmlns:telerikQuickStart="clr-namespace:Telerik.Windows.Controls.QuickStart;assembly=Telerik.Windows.Controls"

             xmlns:tileview="clr-namespace:Telerik.Windows.Controls.TileView;assembly=Telerik.Windows.Controls.Navigation"

             xmlns:MyNamespace="clr-namespace:StaticMap;assembly=StaticMap"

      xmlns:local="clr-namespace:PendDelBrowser"

      mc:Ignorable="d"

      d:DesignHeight="300" d:DesignWidth="1000"

      Title="Pending Delivery">

    <Page.Resources >

    </Page.Resources>

    <Grid>

        <Grid.RowDefinitions>

            <RowDefinition Height="*" />

            <RowDefinition Height="31" />

            </Grid.RowDefinitions>

            <Grid.Resources >

            <local:NullStringtoBackColor x:Key="BackColorConvertor" />

            <local:NullToStringConvertor x:Key="StringNullConvertor" />

            <local:VisibilityConvertor x:Key="VisibilityConvertor" />

            <local:BoolToTileStateConverter x:Key="Ismax" />

            <local:FontConvertor x:Key="FontColourConvertor" />

            <tileview:TileToFluideStateConverter x:Key="tileConverter" />

            <Style x:Key="TileViewItemHeaderStyle1" TargetType="tileview:TileViewItemHeader">

                <Setter Property="Foreground" Value="White"  />

                <Setter Property="Background"   Value="{Binding Vehicle}"   />

                <Setter Property="FontSize" Value="14" />

                <Setter Property="FontFamily" Value="Segoe UI" />

            </Style>

            <Style TargetType="telerik:RadTileViewItem">

                <Setter Property="Padding" Value="3" />

                <Setter Property="BorderBrush" Value="Transparent" />

                <Setter Property="Background" Value="Transparent" />

                <Setter Property="BorderThickness" Value="0" />

                <Setter Property="TileState" Value="{Binding MyTileState, Mode=TwoWay}" />

                <Setter Property="HeaderStyle" Value="{StaticResource TileViewItemHeaderStyle1}" />

            </Style>

            <Style TargetType="telerik:RadTileView">

                <Setter Property="PreservePositionWhenMaximized" Value="True" />

                <Setter Property="telerik:TileViewPanel.IsVirtualized" Value="True" />

                <Setter Property="IsAutoScrollingEnabled" Value="True" />

                <Setter Property="TileStateChangeTrigger" Value="SingleClick" />

                <Setter Property="MinimizedColumnWidth" Value="308" />

                <Setter Property="MinimizedRowHeight" Value="173" />

                <Setter Property="RowHeight" Value="167" />

                <Setter Property="ColumnWidth" Value="277" />

                <Setter Property="ColumnsCount" Value="4" />

                <Setter Property="Foreground" Value="#FFEE1515"/>

            </Style>

            <DataTemplate x:Key="contentTemplate">

                <telerik:RadFluidContentControl ContentChangeMode="Manual"

                                                    State="Normal"

                                                    TransitionDuration="0:0:.7">

                    <telerik:RadFluidContentControl.Content>

                        <Border Background="{Binding BackCol}">

                            <Grid Margin="2 2">

                                <StackPanel >

                                    <TextBlock

                                                                FontFamily="Segoe UI"

                                                                FontSize="24"

                                                                FontWeight="Medium"

                                                                Foreground="{Binding BackCol, Converter={StaticResource FontColourConvertor},ConverterParameter={Binding BackCol}}"

                                         Text="{Binding JobNum}" />

                                    <StackPanel Orientation="Horizontal" >

                                        <TextBlock FontSize="14"

                                                                Foreground="#000"

                                                                Text="Deliver To:" />

                                        <TextBlock FontSize="14"

                                                                Foreground="#000"

                                                                Text="{Binding DelName}" />

                                    </StackPanel>

                                    <Border Height="2"

                                                             Margin="0 5"

                                                             Background="#000" />

                                    <StackPanel Orientation="Horizontal" >

                                        <TextBlock FontSize="14" TextWrapping="Wrap"

                                                                Foreground="#000" Text="{Binding Location}" />

                                        <TextBlock FontSize="14"

                                                                Foreground="Black" Text="{Binding DelDate, StringFormat={}{0:HH:mm}}" />

                                    </StackPanel>

                                </StackPanel>

                                <TextBlock Margin="0 0 0 0"

                                                                FontFamily="Segoe UI"

                                                                FontSize="24"

                                                                FontWeight="Light"

                                                                Foreground="Black"

                                       TextAlignment="Right"

                                                                Text="{Binding Tdiff}" />

                                <Image HorizontalAlignment="Right"

                                                      VerticalAlignment="Bottom"

                                   Margin="2 2 2 2"

                                   Width="32"

                                   Height="32"

                                                      Source="{Binding Icon}"

                                                      Stretch="Fill" />

                            </Grid>

                        </Border>

                    </telerik:RadFluidContentControl.Content>

                    <telerik:RadFluidContentControl.LargeContent>

                        <Grid Margin="2 2 2 2">

                            <Grid.ColumnDefinitions>

                                <ColumnDefinition Width="*" />

                            </Grid.ColumnDefinitions>

                            <telerik:RadTabControl DropDownDisplayMode="Visible" ScrollMode="Viewport" BorderThickness="0">

                                <telerik:RadTabItem DropDownContent="Location Map" Header="Map" >

                                    <StackPanel Orientation="Horizontal" Margin="5 10 0 0" Grid.ColumnSpan="2" >

                                        <MyNamespace:MapBlock my_Address="{Binding Path=LatLng}"/>

                                    </StackPanel>

                                </telerik:RadTabItem>

                                <telerik:RadTabItem DropDownContent="Joe Details" Header="Job Details" FontSize="16" FontFamily="Segoe UI" Background="Black" Foreground="White" >

                                    <StackPanel>

                                        <StackPanel Orientation="Horizontal" Margin="2 2 2 2" >

                                            <TextBlock Text="Job Number: "/>

                                            <TextBlock Text="{Binding JobNum}" />

                                        </StackPanel>

                                    </StackPanel>

                                </telerik:RadTabItem>

                                <telerik:RadTabItem DropDownContent="Temp History" Header="Temp" Visibility="{Binding Temp1, Converter={StaticResource VisibilityConvertor}}" FontSize="16" FontFamily="Segoe UI" Background="Black" Foreground="White" >

                                    <StackPanel>

                                        <StackPanel Orientation="Horizontal" Margin="0 2 2 2" Background="LightSteelBlue" >

                                            <Grid x:Name="TempGrid" >

                                                <Grid.ColumnDefinitions>

                                                    <ColumnDefinition Width="40" />

                                                    <ColumnDefinition Width="*" />

                                                </Grid.ColumnDefinitions>

                                                <telerik:RadGridView x:Name="TempGridview" Grid.Column="1" Grid.ColumnSpan="1" ShowGroupPanel="False" >

                                                </telerik:RadGridView>

                                            </Grid>

                                        </StackPanel>

                                    </StackPanel>

                                </telerik:RadTabItem>

                            </telerik:RadTabControl>

                        </Grid>

                    </telerik:RadFluidContentControl.LargeContent>

                </telerik:RadFluidContentControl>

            </DataTemplate>

            <DataTemplate x:Key="headerTemplate">

                <StackPanel Orientation="Horizontal">

                    <TextBlock Text="Vehicle " />

                    <TextBlock Text="{Binding Registration}" />

                </StackPanel>

            </DataTemplate>

        </Grid.Resources>

        <Grid>

            <Grid.Resources >

                <local:NullStringtoBackColor x:Key="BackColorConvertor" />

                <local:NullToStringConvertor x:Key="StringNullConvertor" />

                <local:VisibilityConvertor x:Key="VisibilityConvertor" />

                <tileview:TileToFluideStateConverter x:Key="tileConverter" />

                <Style x:Key="TileViewItemHeaderStyle1" TargetType="tileview:TileViewItemHeader">

                    <Setter Property="Foreground" Value="White"  />

                    <Setter Property="Background"   Value="{Binding Vehicle}"   />

                    <Setter Property="FontSize" Value="14" />

                    <Setter Property="FontFamily" Value="Segoe UI" />

                </Style>

                <Style TargetType="telerik:RadTileViewItem">

                    <Setter Property="Padding" Value="3" />

                    <Setter Property="BorderBrush" Value="Transparent" />

                    <Setter Property="Background" Value="Transparent" />

                    <Setter Property="TileState" Value="{Binding MyTileState, Mode=TwoWay}" />

                    <Setter Property="BorderThickness" Value="0" />

                    <Setter Property="HeaderStyle" Value="{StaticResource TileViewItemHeaderStyle1}" />

                </Style>

                <Style TargetType="telerik:RadTileView">

                    <Setter Property="PreservePositionWhenMaximized" Value="True" />

                    <Setter Property="telerik:TileViewPanel.IsVirtualized" Value="True" />

                    <!--<Setter Property="IsAutoScrollingEnabled" Value="True" />-->

                    <Setter Property="TileStateChangeTrigger" Value="SingleClick" />

                    <Setter Property="MinimizedColumnWidth" Value="308" />

                    <Setter Property="MinimizedRowHeight" Value="173" />

                    <Setter Property="RowHeight" Value="167" />

                    <Setter Property="ColumnWidth" Value="277" />

                    <Setter Property="ColumnsCount" Value="4" />

                    <Setter Property="Foreground" Value="#FFEE1515"/>

                </Style>

                <DataTemplate x:Key="contentTemplate">

                    <telerik:RadFluidContentControl ContentChangeMode="Automatic"

                                                    State="Normal"

                                                    TransitionDuration="0:0:.7">

                        <telerik:RadFluidContentControl.Content>

                            <Border Background="{Binding BackCol}">

                                <Grid Margin="2 2">

                                    <StackPanel >

                                        <TextBlock

                                                                FontFamily="Segoe UI"

                                                                FontSize="24"

                                                                FontWeight="Medium"

                                                                Foreground="Black"

                                         Text="{Binding JobNum}" />

                                        <StackPanel Orientation="Horizontal" >

                                            <TextBlock FontSize="14"

                                                                Foreground="#000"

                                                                Text="Deliver To:" />

                                            <TextBlock FontSize="14"

                                                                Foreground="Black"

                                                                Text="{Binding DelName}" />

                                        </StackPanel>

                                        <Border Height="2"

                                                             Margin="0 5"

                                                             Background="#000" />

                                        <StackPanel Orientation="Horizontal" >

                                            <TextBlock FontSize="14" TextWrapping="Wrap"

                                                                Foreground="#000" Text="{Binding Location}" />

                                            <TextBlock FontSize="14"

                                                                Foreground="#000" Text="{Binding DelDate, StringFormat={}{0:HH:mm}}" />

                                        </StackPanel>

                                    </StackPanel>

                                    <TextBlock Margin="0 0 0 0"

                                                                FontFamily="Segoe UI"

                                                                FontSize="24"

                                                               FontWeight="Light"

                                                                Foreground="Black"

                                       TextAlignment="Right"

                                                                Text="{Binding Tdiff}" />

                                    <Image HorizontalAlignment="Right"

                                                      VerticalAlignment="Bottom"

                                   Margin="2 2 2 2"

                                   Width="32"

                                   Height="32"

                                                      Source="{Binding Icon}"

                                                      Stretch="Fill" />

                                </Grid>

                            </Border>

                        </telerik:RadFluidContentControl.Content>

                        <telerik:RadFluidContentControl.LargeContent>

                            <Grid Margin="2 2 2 2">

                                <Grid.ColumnDefinitions>

                                    <ColumnDefinition Width="*" />

                                </Grid.ColumnDefinitions>

                                <telerik:RadTabControl DropDownDisplayMode="Visible" ScrollMode="Viewport" BorderThickness="0">

                                    <telerik:RadTabItem DropDownContent="Location Map" Header="Map" >

                                        <StackPanel Orientation="Horizontal" Margin="5 10 0 0" Grid.ColumnSpan="2" >

                                            <MyNamespace:MapBlock my_Address="{Binding Path=LatLng}"/>

                                        </StackPanel>

                                    </telerik:RadTabItem>

                                    <telerik:RadTabItem DropDownContent="Joe Details" Header="Job Details" FontSize="16" FontFamily="Segoe UI" Background="Black" Foreground="White" >

                                                <Grid >

                                                    <Grid.ColumnDefinitions>

                                                        <ColumnDefinition Width="125" />

                                                        <ColumnDefinition Width="150" />

                                                    </Grid.ColumnDefinitions>

                                                <StackPanel >

                                                    <TextBlock Text="Job Number: " Grid.Column="1"/>

                                                <TextBlock Text="{Binding JobNum}" Grid.Column="1"/>

                                                </StackPanel>

                                                <StackPanel >

                                                    <TextBlock Text="Job Number number two : " Grid.Column="2"/>

                                                    <TextBlock Text="{Binding JobNum}" Grid.Column="1"/>

                                                </StackPanel>

                                           </Grid> </telerik:RadTabItem>

                                    <telerik:RadTabItem DropDownContent="Temp History" Header="Temp" Visibility="{Binding Temp1, Converter={StaticResource VisibilityConvertor}}" FontSize="16" FontFamily="Segoe UI" Background="Black" Foreground="White" >

                                        <StackPanel>

                                            <StackPanel Orientation="Horizontal" Margin="0 2 2 2" Background="LightSteelBlue" >

                                                <Grid x:Name="TempGrid" >

                                                    <Grid.ColumnDefinitions>

                                                        <ColumnDefinition Width="40" />

                                                        <ColumnDefinition Width="*" />

                                                    </Grid.ColumnDefinitions>

                                                    <telerik:RadGridView x:Name="TempGridview" Grid.Column="1" Grid.ColumnSpan="1" ShowGroupPanel="False"

                                                                         ItemsSource="{Binding  TempHist}" >

                                                    </telerik:RadGridView>

                                                </Grid>

                                            </StackPanel>

                                        </StackPanel>

                                    </telerik:RadTabItem>

                                </telerik:RadTabControl>

                            </Grid>

                        </telerik:RadFluidContentControl.LargeContent>

                    </telerik:RadFluidContentControl>

                </DataTemplate>

                <DataTemplate x:Key="headerTemplate">

                    <StackPanel Orientation="Horizontal">

                        <TextBlock Text="Vehicle " />

                        <TextBlock Text="{Binding Registration}" />

                    </StackPanel>

                </DataTemplate>

            </Grid.Resources>

            <telerik:RadTileView   

                                 ContentTemplate="{StaticResource contentTemplate}"

                                 IsItemDraggingEnabled="{Binding ElementName=IsItemDraggingEnabledOption,

                                                                 Path=IsChecked}"

                                 ItemsSource="{Binding Items}"

                                 ItemTemplate="{StaticResource headerTemplate}"

                                  Name="RadTileView1" />

          

        </Grid>

 

0
Tina Stancheva
Telerik team
answered on 02 Mar 2012, 12:39 PM
Hi Joe,

From the xaml code you sent I am not sure what might be causing the issue. However, I noticed that you bind the TileState of each RadTileViewItem but if you want to dynamically change the RadFluidContentControl content based on the state of the tiles, you will need to bind the RadFluidContentControl.State property as well. You can try the approach described here.

If the synchronization of the RadTileViewItems' state and the RadFluidContentControl.State properties doesn't help, it would be best to create a support ticket and attach in it a sample demonstrating your scenario. Then we will be able to further examine it and look for what is causing the tile state changes.

Greetings,
Tina Stancheva
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Tags
TileView
Asked by
Joe Bohen
Top achievements
Rank 1
Answers by
Kiril Stanoev
Telerik team
Joe Bohen
Top achievements
Rank 1
Tina Stancheva
Telerik team
Share this question
or