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

Access webbrowser inside ExpandableContentTemplate

6 Answers 79 Views
ExpanderControl
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Marcus
Top achievements
Rank 2
Marcus asked on 09 Feb 2013, 08:36 PM
Hi,

how can I access a webbrowser element out of a list of multiple expandercontrol items within RadDataBoundListBox

Here is my XAML Code. I want to NavigateToString() once the user expanded the control and some more stuff. However, I am having difficulties accessing the webbrowser element. Following is the XAML Code which I am using to implement the webbrowser in the RadExpanderControl.
Thanks for help!

<telerikPrimitives:RadDataBoundListBox  ItemsSource="{Binding ContentItems}"
                    Margin="12,3"
                    x:Name="DataBoundListBox">
<telerikPrimitives:RadDataBoundListBox.ItemTemplate>
<DataTemplate>
<telerikPrimitives:RadExpanderControl x:Name="ExpanderCtl"
                       BorderThickness="4, 0, 0, 0"
                       BorderBrush="{StaticResource PhoneAccentBrush}"
                       Foreground="{StaticResource PhoneForegroundBrush}"
                       ExpandedStateChanged = "ContentExpander_StateChanged">
<telerikPrimitives:RadExpanderControl.ContentTemplate>
<DataTemplate>
<StackPanel Margin="8, 4 ,4 ,4"
       Orientation="Horizontal">
<Image Source="Images/Frame.png"
    Width="64"
    Height="64"
    Margin="0,4,12,4" />
<TextBlock  FontSize="{StaticResource PhoneFontSizeExtraLarge}"
       FontFamily="{StaticResource PhoneFontFamilyLight}"
       Text="{Binding Title}"
       VerticalAlignment="Center" />
</StackPanel>
</DataTemplate>
</telerikPrimitives:RadExpanderControl.ContentTemplate>
<telerikPrimitives:RadExpanderControl.ExpandableContentTemplate>
<DataTemplate>
<phone:WebBrowser x:Name="WebView"
   Source="{Binding Uri1}"
   IsScriptEnabled="True"
   Height="200"
   HorizontalAlignment="Stretch"
   VerticalAlignment="Stretch" />
</DataTemplate>
</telerikPrimitives:RadExpanderControl.ExpandableContentTemplate>
</telerikPrimitives:RadExpanderControl>
</DataTemplate>
</telerikPrimitives:RadDataBoundListBox.ItemTemplate>
</telerikPrimitives:RadDataBoundListBox>

6 Answers, 1 is accepted

Sort by
0
Deyan
Telerik team
answered on 14 Feb 2013, 07:39 AM
Hi Marcus,

Thanks for writing.

I have handled the Support ticket you have opened regarding the same case.

In short, you can use the ExpandedStateChanged event of the Expander Control and use the Sender parameter within the event handler to iterate over the element tree of the control and find the web browser inside.

Let me know should you have further questions or need assistance.

All the best,
Deyan
the Telerik team
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
0
Marcus
Top achievements
Rank 2
answered on 15 Feb 2013, 03:21 PM
Hi Deyan,

things work fine now. If anyone is interested, I solved it in a different way as the result I got out of the ElementTreeHelper was a webbrowser but it does not seemed to be referencing back to the element in xaml. Therefore, I could not update things in the real existing element. Well, maybe I just do not know how things work but anyway, I solved it with a simple "Loaded" event in XAML  webbrowser element (Loaded="htmlviewer_Loaded_1") and in this event I used the sender object to modify the webbrowser component. 

BUT, now I have another issue. As you can see in the xaml in the first post, I have a RadDataBoundListBox wrapped around my whole content. This is the root of the whole list. Now when I expand an element, I am able to get the elements from the RadExpanderControl. However, I want to get the Index of the Item which contains the currently expanded RadExpanderControl.

So I could get the index with an IndexOf on the selected RadDataBoundListBox Item but in this case, a subitem event from the RadExpanderControl is called (ExpandedStateChanged) and not the "selectionChanged" event from the ListBox.

It is probably possible with the VisualTreeHelper.GetParent() but I am not sure if that would return a corrent index and not only the whole item?

Thanks for a hint here!

Best regards,
Marcus
0
Marcus
Top achievements
Rank 2
answered on 15 Feb 2013, 10:16 PM
Alright, solved this one as well. Turns out that with...

this.DataBoundListBox.SelectedItem = ((RadExpanderControl)sender).DataContext;

... I was able to set the selected Item to the item in the ancestor RadDataBoundList. Strangely, it did not returned the correct index. It is always 0 but the selected item was correct. So I just grabbed the stuff I needed from the selected item itself instead going back to the collection and get it from there. Quite easy:
FileViewModel selection = this.DataBoundListBox.SelectedItem as FileViewModel;
string selhtml = selection.BrowserContent.ToString();

Note that FileViewModel is my custom class/object to hold the data for the list. BrowserContent is a string which I get out of the custom class.

regards!
0
Deyan
Telerik team
answered on 19 Feb 2013, 08:08 AM
Hi Marcus,

Good that you've managed to resolve the case.

We will now consider both of your tickets regarding this topic closed.

Feel free to contact us anytime in case of further questions.

All the best,
Deyan
the Telerik team
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
0
Marcus
Top achievements
Rank 2
answered on 19 Feb 2013, 09:08 AM
Hi Deyan,

please do not close the tickets as they revolve around completely different issues with RadExpanderControl. One might actually be a bug.

Thanks!

Best Regards,
Marcus
0
Deyan
Telerik team
answered on 22 Feb 2013, 08:43 AM
Hi Marcus,

We will be addressing a couple of issues of RadExpanderControl's integration with RadDataBoundListBox.

1. We will address a glitch which prevents the correct update of expander's header and content.

2. We will allow binding the IsExpanded property of the RadExpanderControl to a property on the viewmodel to control whether the expander is expanded or not. This behavior currently is not implemented in this way.

Let me know if there are further issues you would like to have addressed.

All the best,
Deyan
the Telerik team
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
Tags
ExpanderControl
Asked by
Marcus
Top achievements
Rank 2
Answers by
Deyan
Telerik team
Marcus
Top achievements
Rank 2
Share this question
or