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

Binding to a string

6 Answers 116 Views
HTMLPlaceHolder
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 1
Andrew asked on 02 Oct 2010, 10:39 PM
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?

6 Answers, 1 is accepted

Sort by
0
Andrew
Top achievements
Rank 1
answered on 03 Oct 2010, 09:07 PM
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.
0
Tina Stancheva
Telerik team
answered on 06 Oct 2010, 04:37 PM
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
0
Andrew
Top achievements
Rank 1
answered on 06 Oct 2010, 06:25 PM
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?

0
Tina Stancheva
Telerik team
answered on 12 Oct 2010, 12:44 PM
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
0
laxman
Top achievements
Rank 1
answered on 19 Jan 2011, 11:46 PM
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
0
Petar Mladenov
Telerik team
answered on 24 Jan 2011, 03:42 PM
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>>
Tags
HTMLPlaceHolder
Asked by
Andrew
Top achievements
Rank 1
Answers by
Andrew
Top achievements
Rank 1
Tina Stancheva
Telerik team
laxman
Top achievements
Rank 1
Petar Mladenov
Telerik team
Share this question
or