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

RadPanelBar Hierarchical SelectedItem Binding

2 Answers 107 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
Benedikt
Top achievements
Rank 3
Iron
Iron
Iron
Benedikt asked on 04 Oct 2019, 08:21 AM

Hello together,

I use a RadPanelBar to display a List of Dates in a range grouped by week (to better understand I added a picture). If I click a day I want to load right beside it a Datatable into a RadGridView based on the date I selected.

I managed to bind the RadPanelBar to my ViewModel:

<telerik:RadPanelBar
    Grid.Column="0"
    x:Name="rpbKWs"
    ExpandMode="Multiple"
    ItemsSource="{Binding WochenAnzeige}"
    SelectedItem="{Binding selTag, Mode=TwoWay}"
    >
    <telerik:RadPanelBar.ItemTemplate>
        <HierarchicalDataTemplate
            ItemsSource="{Binding TageAnzeige}"
            >
            <HierarchicalDataTemplate.ItemTemplate>
                <DataTemplate>
                    <StackPanel>
                        <TextBlock
                            FontWeight="Medium"
                            Text="{Binding Path=Datum, StringFormat={}{0:dd.MM.yyyy}}"
                            />
                        <TextBlock
                            Margin="0 5 0 0"
                            FontSize="{StaticResource Caption}"
                            Text="{Binding Path=Einträge, StringFormat={}Einträge: {0}}"
                            />
                        <TextBlock
                            Margin="0 2 0 0"
                            FontSize="{StaticResource Caption}"
                            Text="{Binding Path=EinträgeImWerk, StringFormat={}davon im Werk: {0}}"
                            />
                        <TextBlock
                            Margin="0 2 0 0"
                            FontSize="{StaticResource Caption}"
                            Text="{Binding Path=EinträgeMontageEingeteilt, StringFormat={}davon in Montage: {0}}"
                            />
                    </StackPanel>
                </DataTemplate>
            </HierarchicalDataTemplate.ItemTemplate>
            <StackPanel>
                <TextBlock
                    FontWeight="Medium"
                    >
                    <TextBlock.Text>
                        <MultiBinding
                            StringFormat="{}KW {0} Jahr {1}"
                            >
                            <Binding
                                Path="KW"
                                />
                            <Binding
                                Path="Jahr"
                                />
                        </MultiBinding>
                    </TextBlock.Text>
                </TextBlock>
                <TextBlock
                    FontSize="{StaticResource Caption}"
                    >
                    <TextBlock.Text>
                        <MultiBinding
                            StringFormat="{}{0:dd.MM.yy} - {1:dd.MM.yy}"
                            >
                            <Binding
                                Path="MinDatum"
                                />
                            <Binding
                                Path="MaxDatum"
                                />
                        </MultiBinding>
                    </TextBlock.Text>
                </TextBlock>
                <TextBlock
                    Margin="0 5 0 0"
                    FontSize="{StaticResource Caption}"
                    Text="{Binding Path=Einträge, StringFormat={}Einträge: {0}}"
                    />
                <TextBlock
                    Margin="0 2 0 0"
                    FontSize="{StaticResource Caption}"
                    Text="{Binding Path=EinträgeImWerk, StringFormat={}davon im Werk: {0}}"
                    />
                <TextBlock
                    Margin="0 2 0 0"
                    FontSize="{StaticResource Caption}"
                    Text="{Binding Path=EinträgeMontageEingeteilt, StringFormat={}davon in Montage: {0}}"
                    />
            </StackPanel>
        </HierarchicalDataTemplate>
    </telerik:RadPanelBar.ItemTemplate>
</telerik:RadPanelBar>

But have problems with the SelectedItem. The days and weeks are different classes, because they contain different properties for example the week contains a List of days.
If I bind the SelectedItem to the 'selTag' and set a selTag in code nothing happens.

If I change the Selection in UI the property is updated, so this part works.
But if I select a week in UI my whole RadPanelBar gets a red border I don't understand where it comes from. Maybe because a week is a different class then a day and cant be updated because of that?

Is there a way to bind the SelectedItem poperty of a hierarchical RadPanelBar for the parent and chield levels seperately? Or some compleetely different solution?

I have uploaded my project here: https://www.dropbox.com/s/dxbaignaf8rxcx7/ReklamationsManagement.zip?dl=0

It will definitely not run because a sql connection and has some things in it I not longer use, but maybe you better understand my classes there.

Greetings

Benedikt

2 Answers, 1 is accepted

Sort by
0
Accepted
Dinko | Tech Support Engineer
Telerik team
answered on 08 Oct 2019, 01:12 PM

Hello Benedikt,

Thank you for the provided project and information.

Looking at the project the SelectedItem of the RadPanelBar is bound to a property of type clsTag. That why it is not working as expected. Both clsTag and clsWoche classes derive from clsBaseViewModel class. You can change the type of selTag property to clsBaseViewModel. Then in the setter, there's ReklamationenAktualisieren() method. Inside the method, you can check the type of the selTag property and execute your logic. Check the following code snippets.

public clsBaseViewModel mselTag;
public clsBaseViewModel selTag 
{ 
    get
    {
        return mselTag;
    }
    set
    {
        if (value != mselTag)
        {
            mselTag = value;

            if (Initialized)
            {
                ReklamationenAktualisieren();
            }
        }
    }
}
 . . . . 
private void ReklamationenAktualisieren()
{
    if(selTag is clsTag)
    {
        clsDaten.GibReklamationenMitDatumUndProduktGruppe((selTag as clsTag).Datum, ProduktGruppe);

        dtReklamationen.Clear();
        clsGlobaleVariablen.daReklamationen.Fill(dtReklamationen);
    }
    else if(selTag is clsWoche)
    {
        //other logic here.
    }  
}

Hope this approach will work for you.

Regards,
Dinko
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Benedikt
Top achievements
Rank 3
Iron
Iron
Iron
answered on 08 Oct 2019, 01:39 PM

Hi Dinko,

 

easy and great solution.

Thanks for the quick response.

 

Greetings,

Benedikt

Tags
PanelBar
Asked by
Benedikt
Top achievements
Rank 3
Iron
Iron
Iron
Answers by
Dinko | Tech Support Engineer
Telerik team
Benedikt
Top achievements
Rank 3
Iron
Iron
Iron
Share this question
or