Access webbrowser inside ExpandableContentTemplate

7 posts, 0 answers
  1. Marcus
    Marcus avatar
    24 posts
    Member since:
    Jul 2012

    Posted 09 Feb 2013 Link to this post

    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>
  2. Deyan
    Admin
    Deyan avatar
    2039 posts

    Posted 14 Feb 2013 Link to this post

    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.
  3. DevCraft banner
  4. Marcus
    Marcus avatar
    24 posts
    Member since:
    Jul 2012

    Posted 15 Feb 2013 Link to this post

    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
  5. Marcus
    Marcus avatar
    24 posts
    Member since:
    Jul 2012

    Posted 15 Feb 2013 Link to this post

    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!
  6. Deyan
    Admin
    Deyan avatar
    2039 posts

    Posted 19 Feb 2013 Link to this post

    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.
  7. Marcus
    Marcus avatar
    24 posts
    Member since:
    Jul 2012

    Posted 19 Feb 2013 Link to this post

    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
  8. Deyan
    Admin
    Deyan avatar
    2039 posts

    Posted 22 Feb 2013 Link to this post

    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.
Back to Top
DevCraft banner