Binding to a string

7 posts, 0 answers
  1. Andrew
    Andrew avatar
    68 posts
    Member since:
    Jul 2010

    Posted 02 Oct 2010 Link to this post

    I want to use HTMLPlaceHolder instead of a textbox to display this string, because it has formatted HTML content.  I cannot figure out how to bind it.

    Here is what is working
    In code

    this.lb.ItemsSource = dds.Data;


    IN xaml
    <ListBox Name="lb" Height="629">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <TextBox Text="{Binding LongDescription}" TextWrapping="Wrap" Height="600" Width="800"/>
                  
      
                </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
    I cannot figure out the xaml and code to accomplish the same result with your html control
    I have tried

    this

     

     

    .lb.HtmlSource =
    but I cannot figure out how to address the actual field LongDescription as opposed to the entire dds.Data
    Is there a way to bind it in XAML or code?
    Should I be using a different control?

  2. Andrew
    Andrew avatar
    68 posts
    Member since:
    Jul 2010

    Posted 03 Oct 2010 Link to this post

    I have also tried this with RadRichTextBox with no success.

    Someone must know how to bind either the RadRichTextBox or the HTMLPlaceHolder to a data source with an HTML string.
  3. DevCraft banner
  4. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 06 Oct 2010 Link to this post

    Hello Andrew,

    I prepared a sample project illustrating how to implement the desired scenario using a RadHtmlPlaceHolder and a RadRichTextBox. Please take a look at it and let me know if it works for you.

    Kind regards,
    Tina Stancheva
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Andrew
    Andrew avatar
    68 posts
    Member since:
    Jul 2010

    Posted 06 Oct 2010 Link to this post

    Error: Unhandled Error in Silverlight Application
    Code: 4004   
    Category: ParserError      
    Message: The invocation of the constructor on type 'Telerik.Windows.Controls.RadHtmlPlaceholder' that matches the specified binding constraints threw an exception.    
    File:     
    Line: 25    
    Position: 56    

    I took your code
     
    code behind
      
                storeDomainContext ctx = new storeDomainContext();
                dds.QueryName = "GetProductDetailsQuery";
                dds.DomainContext = ctx;
                dds.AutoLoad = true
                filterPD.PropertyPath = "ProdID";
                filterPD.Operator = FilterOperator.IsEqualTo;
                filterPD.Value =pvalue;
                dds.FilterDescriptors.Add(filterPD);
                this.lb.ItemsSource = dds.Data;
                try
                {
                    dds.Load();
                      
                            }
                catch
                {
                      
                }
      
    XAML
      
            <ListBox Name="lb" Height="629">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <telerik:RadHtmlPlaceholder Height="600" Width="800" HtmlSource="{Binding LongDescription}"/>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>

    what does this error tell you?

  6. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 12 Oct 2010 Link to this post

    Hello Andrew,

    I cannot be entirely sure what is causing this issue, however such exceptions might be raised if the Silverlight plug-in isn't in a windowless mode. It is important to note that the Silverlight plug-in that hosts the RadHtmlPlaceHolder control has to be Windowless enabled. For example if the Silverlight application is hosted in an html page, then:
    <div id="silverlightControlHost">
    <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
     <param name="source" value="ClientBin/RadHtmlPlachoderDemo.xap"/>
     <param name="onerror" value="onSilverlightError" />
     <param name="background" value="white" />
     <param name="minRuntimeVersion" value="2.0.31005.0" />
     <param name="autoUpgrade" value="true" />
     <param name="windowless" value="true" />
     <a href="http://go.microsoft.com/fwlink/?LinkID=124807" style="text-decoration: none;">
      <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/>
     </a>
    </object>
    <iframe style='visibility:hidden;height:0;width:0;border:0px'></iframe>
    </div>

    Also, since the default ItemsPanel of the ListBox is the VirtualizingStackPanel, this might also be a cause for exceptions with the RadHtmlPlaceHolder, so in your scenario I would recommend changing the  default ItemsPanel of the ListBox:
    <ListBox Name="lb">
        <ListBox.ItemsPanel>
            <ItemsPanelTemplate>
                <StackPanel />
            </ItemsPanelTemplate>
        </ListBox.ItemsPanel>
        <ListBox.ItemTemplate>
            <DataTemplate>
                <telerik:RadHtmlPlaceholder Height="600" Width="800" HtmlSource="{Binding Text}" />
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>

    I hope this info helps. Please give it a try and let me know if it works for you.

    Greetings,
    Tina Stancheva
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  7. laxman
    laxman avatar
    9 posts
    Member since:
    Jan 2011

    Posted 19 Jan 2011 Link to this post

    Hi,
    I need something like this;
    I am adding RadRibbonDropDownButton to radRibbon.
    Than I am adding ListBox to the RadRibbonDropDownButton .
    Here is the code in View.

    private void AddItemsToRibbon
    {
        _HeaderFooterBindingButton = new RadRibbonDropDownButton()
                {
                    Text ="Header/Footer Binding",
                    Size = ButtonSize.Large
                };

                _HeaderFooterBindingListBox = new ListBox()
                {
                    VerticalContentAlignment = System.Windows.VerticalAlignment.Center,
                    HorizontalContentAlignment = HorizontalAlignment.Left,
                    Width = 150,
                    Height = 75,
                };

                var sv = new ScrollViewer() { Height = 100, Content = _HeaderFooterBindingListBox };
                var stackPanel = new StackPanel() { Orientation = System.Windows.Controls.Orientation.Vertical };

                stackPanel.Children.Add(sv);

                var customMenuItem = new RadMenuItem() { Header = "New..." };
                stackPanel.Children.Add(customMenuItem);

                _PageLayoutGroup.Items.Add(_HeaderFooterBindingButton);

                AddHeaderFooterTemplateBindings();

                _HeaderFooterBindingButton.DropDownContent = stackPanel;
    }

            private void AddHeaderFooterTemplateBindings()
            {
                var binding = new Binding();
                binding.Mode = BindingMode.OneWay;
                binding.Path = new PropertyPath("Templates");
                _HeaderFooterBindingListBox.SetBinding(ItemsSourceProperty, binding);

                var binding1 = new Binding();
                binding1.Mode = BindingMode.TwoWay;
                binding1.Path = new PropertyPath("SelectedTemplate");
                _HeaderFooterBindingListBox.SetBinding(Selector.SelectedItemProperty, binding1);
            }

    I have  "Templates" and "SelectedTemplate" in Model.

    the list box is loaded with the data but I am not able to select or mouse over or click the item in the list box..
    Also SelectedItemProperty binding property is not working at all.

    If I put RadRibbonComboBox directly on Ribbon than it works fine.

    Any help will be appreciated.

    Thanks,
    Laxman
  8. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 24 Jan 2011 Link to this post

    Hi Andrew,

    Since we were having many issues with our Telerik.Windows.Controls.ListBox, we announced it as an obsolete control. We highly recommend you to use System.Windows.Controls.ListBox like it is done in the attached sample. Please give it a try and let us know how it goes.

    All the best,
    Petar Mladenov
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Back to Top
DevCraft banner