Telerik Forums
UI for WPF Forum
8 answers
516 views

Hello,

Let's start by explaining what I'm trying to achieve. I basically want to bind a single RadRichTextBox to multiple different DataProviders.
In my specific situation one RtfDataProvider and one TxtDataProvider. So that the same text can be bound to two different properties.
Where one property is just plain text and the other has the applied format (rtf).

I just went ahead and just tried it, and to my surprise this actually worked perfectly fine. However when I tried to apply the same technique to a custom RadGridView.RowDetailsTemplate this quit working and only the format of the last defined DataProvider gets applied.

One could think that this isn't really that big of an issue if you just define the RtfDataProver last, because then the RadRichTextBox would always have the correct styles applied.
This train of though would be correct when you can assume that both properties will always contain the same values, which unfortunately is not the case in my specific scenario.

Here is what happened, my model (and corresponding database table) used to only have the property for plain text.
We've recently decided to add an extra property (or column in the database) to save text formatting (rtf).
The great thing about binding both of the properties to the different DataProviders was that even if the rtf-property was empty/null then the RadRichTextBox would still show the plain text and apply default formatting to it.

When using this technique in the RowDetailsTemplate then the following situations occurred:

  • RtfDataProvider is defined last: when the rtf-property is empty the RadRichTextBox will always be empty even when the plain text-property has a value.
  • TxtDataProvider is defined last: the RadRichTextBox will always show some text but won't apply any formatting to it even when there is some defined in the rtf-property.

To explain my scenario better I'll add some code to helpfully make things easier to understand. (This isn't my actual code, just a simpler version to get help sketch an idea)

1. My basic model that represents the table in our database

public class MyTaskObject : INotifyPropertyChanged
{
    private long _taskId;
    public long TaskId
    {
        get { return _taskId; }
        set { SetProperty(ref _taskId, value); }
    }
     
    private string _title;
    public string Title
    {
        get { return _title; }
        set { SetProperty(ref _title, value); }
    }
 
    private string _text;
    public string Text
    {
        get { return _text; }
        set { SetProperty(ref _text, value); }
    }
 
    private string _rtfText;
    public string RtfText
    {
        get { return _rtfText; }
        set { SetProperty(ref _rtfText, value); }
    }
 
    #region Observable
    public event PropertyChangedEventHandler PropertyChanged;
 
    protected void OnPropertyChanged([CallerMemberName] string propName = null)
    {
        var handler = PropertyChanged;
        if (handler != null)
        {
            handler(this, new PropertyChangedEventArgs(propName));
        }
    }
 
    protected bool SetProperty<T>(ref T storage, T value, [CallerMemberName] string propertyName = null)
    {
        if (Equals(storage, value)) return false;
        storage = value;
        OnPropertyChanged(propertyName);
        return true;
    }
    #endregion
   
}

 

2. The first scenario where binding the 2 properties to different DataProviders and a single RadRichTextBox works perfectly as desired.

2.1 This is the Xaml of the view: it's a simple user control that allows the user to search a the database for a specific "task", load it and edit before saving it.
So imagine there to be a buttons to look for "tasks"  and commit or discard the changes.
There are also some textboxes to edit the edit the "Title" property for example, followed by the following:

<telerik:RtfDataProvider x:Name="TaskRtfProvider" Grid.Row="1" Grid.Column="0"  RichTextBox="{Binding ElementName=TaskEditor}"  SetupDocument="DataProviderBase_OnSetupDocument" Rtf="{Binding SelectedTask.RtfText, Mode=TwoWay, UpdateSourceTrigger=Explicit}" />
<telerik:TxtDataProvider x:Name="TaskTxtProvider" Grid.Row="1" Grid.Column="0"  RichTextBox="{Binding ElementName=TaskEditor}" SetupDocument="DataProviderBase_OnSetupDocument"  Text="{Binding SelectedTask.Text, Mode=TwoWay, UpdateSourceTrigger=Explicit}" />
<telerik:RadRichTextBox Grid.Row="1" Grid.Column="0" x:Name="TaskEditor"  Margin="5,0" IsImageMiniToolBarEnabled="True" IsSpellCheckingEnabled="False" Padding="4,2"  FontSize="11pt" FontFamily="Calibri" LayoutMode="Flow"  DocumentInheritsDefaultStyleSettings="True"/>

The UpdateSourceTrigger is Explicit because I use changed tracking and only wish to update the database when the user explicitly says to be clicking a button.
Because if I don't do it this way, and the user loads a task where the "RtfText" property is empty, then immediately after loading this will have a value defined by the default formatting of the RadRichTextBox.

In this first scenario these bindings actually work as they're supposed to.

2.2 The implementation of the SetupDocument-event, this is used to apply some basic formatting (mainly to remove excessive spacing between lines)

private void DataProviderBase_OnSetupDocument(object sender, SetupDocumentEventArgs e)
{
    //var test = sender;
    if (e.Document == null) return;
    e.Document.ParagraphDefaultSpacingAfter = 0;
}

While debugging I've noticed that the second defined DataProvider (in this example the "TaskTxtProvider") does always trigger this event, only when the first DataProvider is null does this event get triggered twice.
Which is exactly what makes this scenario work because this way the RadRichTextBox shows the formatted text if there is any, and else applies the default formatting to the plain text.
This is of course the reason for defining the RtfDataProvider ("TaskRtfProvider")  first.

3. The second scenario is where this stops working, and where I tried to place a RadRichTextBox into the rows of a RadGridView.
In this scenario the RadRichTextBox is purely used for displaying the data, not editing.

                           

Boby
Telerik team
 answered on 31 May 2018
0 answers
114 views

Hi, 

I want to cancel the drag start of a node in treeView. I have seen this link for cancelling drag start. But I couldn't find a way to do it in MVVM. In ViewModel we dont have those DragInitializeEventArgs which I can set data to null to cancel the event.

Please let me know how can I achieve this.

Regards,

Tayyaba

 

Tayyaba
Top achievements
Rank 1
 asked on 31 May 2018
2 answers
214 views

 

 

<Window x:Class="TelerikWpfApp1.MainWindow"
                xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
        xmlns:controls="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <controls:RadGridView x:Name="gridView">
        </controls:RadGridView>
    </Grid>
</Window>

I set Items source in .cs via:

this.gridView.ItemsSource = this.DataTable;

 

DataTable is declared like this:

            Columns =
            {
                new DataColumn("Name", typeof(string)),
                new DataColumn("Name2", typeof(string)),
                new DataColumn("Value", typeof(string)),
            }

 

Without grouping, I see 5 items in the GridView.  I'm able to sort, filter, change column order, edit: everything a developer would expect.  However, if I drag a column up to the grouping pane (to group), the entire items panel is empty.  Ungrouping returns the 5 items.  Basically grouping is just seeming to not work at all.  From the Live Visual tree, there are GridViewGroupRows, but they are empty...no content.  Live Property explorer of the GridViewGroupRow shows there are supposed to be items (4) in it.

I'm using 4.7.1 .NET and C:\Program Files (x86)\Progress\Telerik UI for WPF R1 2018\Binaries\WPF45\Telerik.Windows.Controls.GridView.dll (which claims 2018.1.220.45).  

 

 


Chris
Top achievements
Rank 1
 answered on 30 May 2018
2 answers
683 views

I have a DateTimePicker with InputMode="DatePicker" and TodayButtonVisibility="True".

If I set the SelectableDateEnd property to DateTime.Today (for a date of birth field for example), I can select today's date in the calendar but the Today button is shown disabled. It seems the time of day is taken into account because if I set SelectableDateEnd to DateTime.Now.AddMinutes(5), the Today button remains enabled until 5 minutes have elapsed. I don't know if this is intentional, but it certainly seems inconsistent. 

Claire
Top achievements
Rank 1
 answered on 30 May 2018
2 answers
149 views

I have a radgridview combined with a raddatapager. The data is loaded on demand.

 

The problem i have now is if i have more then 1 page and i click on the column header for sorting i get a threading exception.

How can i fix/bypass the error?

Vladimir Stoyanov
Telerik team
 answered on 30 May 2018
1 answer
285 views

Hi,

I want to set background color of mu autocompletebox as attached file correctback.png but after focusing on autocompletebox it changes background color to default one. So can you please tell me how I can stop changing background color of autocompletebox on set focus to remain same as on lost focus.

Vladimir Stoyanov
Telerik team
 answered on 30 May 2018
6 answers
900 views

A couple of years ago I've created a custom GridViewCell Template that allowed me to set a custom border inside a cell.
All I had to do was change the BorderBrush and BorderThickness properties of the GridViewCell's style.

But since I've updated to a newer version of the control, this has stopped working. Now the left border is missing.
In the past I've had trouble with the bottom border but setting bottom margin to 1 solved that.
However changing the left margin doesn't fix the visibility of the left border.

This is the original custom GridViewCemm Template:

<Style TargetType="telerik:GridViewCell" x:Key="DefaultCellStyle">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="telerik:GridViewCell">
                    <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"  Background="{TemplateBinding Background}">
                            <ContentPresenter  Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" ToolTip="{TemplateBinding ToolTip}" VerticalAlignment="Center" Margin="3,0"/>
                    </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
    <Setter Property="telerik:StyleManager.Theme" Value="Windows8" />
    <Setter Property="Margin" Value="0,0,0,1" />
</Style>

 

An example of how I used this:

<telerik:GridViewDataColumn  Header="Example" DataMemberBinding="{Binding MyBinding}" Width="100">
    <telerik:GridViewDataColumn.CellStyle>
        <Style TargetType="telerik:GridViewCell" BasedOn="{StaticResource DefaultCellStyle}">
            <Setter Property="BorderBrush" Value="Blue"/>
            <Setter Property="BorderThickness" Value="2"/>
        </Style>
    </telerik:GridViewDataColumn.CellStyle>
</telerik:GridViewDataColumn>

 

My previous version of the the control was: 2016.3.1024.45 Here the cell had a perfect border of thickness 2 all-round.
Current version: 2018.1.220.45 Here the left border is missing, the other borders are working fine.

I've tried several things but simply can't get it to work any more.

Sia
Telerik team
 answered on 30 May 2018
2 answers
198 views

hello, I m ashrul

please help me, i cant binding RadRichTextBox and RadListView in my viewmodel, i m using data TxtDataProvider,
that i want is when i type in radrichtextbox and so do RadListView items, please help me guys.

Ashrul
Top achievements
Rank 1
 answered on 30 May 2018
0 answers
383 views

Hi, I'm attempting to use the following example to read in my XML:

https://docs.telerik.com/devtools/wpf/controls/radtreeview/populating-with-data/data-binding-to-xml

 

I am finding that when I convert my items to an ObservableCollection, no results are returned.

 

My XML is as follows:

<?xml version="1.0" encoding="UTF-8"?>
<DocDef Filename="X">
  <DocVars Selected="yes">
    <DocVar Name="JobNumber" Value="0000" Selected="yes"/>
    <DocVar Name="ProjectID" Value="0000" Selected="yes"/>
  </DocVars>
  <DocContent Name="Requirements" Selected="False">
    <DocContent Name="Meeting" Selected="True" />
    <DocContent Name="Quality" Selected="True" />
    <DocContent Name="OHS" Selected="False">
      <DocContent Name="Another thing" Selected="False"/>
    </DocContent>
  </DocContent>
  <DocContent Name="Footer"/>
</DocDef>

 

And my associated XML serialization:

    public class GenericNode
    {
        [XmlAttribute("Name")]
        public String Name { get; set; }

        [XmlAttribute("Selected")]
        public String Selected { get; set; }
    }

    [XmlRoot(ElementName = "DocDef")]
    public class DocDef : GenericNode
    {
        [XmlArray("DocVars")]
        [XmlArrayItem("DocVar", Type = typeof(DocVar))]
        public List<GenericNode> DocVarItems { get; set; }

        [XmlElement("DocContent")]
        public List<DocContentValue> DocContentItems { get; set; }
    }
    
    public class DocVar : GenericNode { }

    public class DocContentValue : GenericNode
    {
        [XmlElement("DocContent")]
        public List<DocContentValue> DocContentItems { get; set; }

    }

 

My issue arises when attempting to extend DocDef as an ObservableCollection<GenericNode> and adding the "AddRange" function:

[XmlRoot(ElementName = "DocDef")]

public class DocDef : ObservableCollection<GenericNode>

{

    public void AddRange( IEnumerable<GenericNode> range )

     {

        foreach (GenericNode node in range)

        {

            this.Add( node );

        }

    }

    ...

If I follow through the rest of the example, AddRange does not add any elements:

 

public class RadTreeViewXmlDataSource : DocDef
    {
        private string source;
        public string Source
        {
            get
            {
                return this.source;
            }
            set
            {
                this.source = value;
                AddRange( RetrieveData( Application.GetResourceStream( new Uri( value, UriKind.Relative ) ).Stream ) );
            }
        }
        private DocDef RetrieveData( Stream xmlStream )
        {
            XmlSerializer serializer = new XmlSerializer( typeof( DocDef ) );
            StreamReader reader = new StreamReader( xmlStream );
            DocDef list = ( DocDef )serializer.Deserialize( reader );
            return list;
        }
    }

 

Any help would be very much appreciated!

 

 

 

Blair
Top achievements
Rank 1
 asked on 29 May 2018
8 answers
759 views

Background:

I have a RadRickTextBox with the following initializiton and I have set AutoInsertHyperlinks="True" in XAML.

private void loaded(object sender, RoutedEventArgs e)
{
    string data = "This is first line\n\n" + "\tUrl: http://www.google.com\n";
    this.radRichTextBox.Insert(data);
}

When I run the code google.com is not "hyperlinked". However, if I move cursor to end of hyperlink and press ENTER, hyperlink is recognized.

Question:

How can I force radRichTextBox to recognize hyperlinks when I insert a string? I have tried UpdateEditorLayout etc but no luck.

 

 

 

Tanya
Telerik team
 answered on 29 May 2018
Narrow your results
Selected tags
Tags
GridView
General Discussions
Chart
RichTextBox
Docking
ScheduleView
ChartView
TreeView
Diagram
Map
ComboBox
TreeListView
Window
RibbonView and RibbonWindow
PropertyGrid
DragAndDrop
TabControl
TileView
Carousel
DataForm
PDFViewer
MaskedInput (Numeric, DateTime, Text, Currency)
AutoCompleteBox
DatePicker
Buttons
ListBox
GanttView
PivotGrid
Spreadsheet
Gauges
NumericUpDown
PanelBar
DateTimePicker
DataFilter
Menu
ContextMenu
TimeLine
Calendar
Installer and Visual Studio Extensions
ImageEditor
BusyIndicator
Expander
Slider
TileList
PersistenceFramework
DataPager
Styling
TimeBar
OutlookBar
TransitionControl
FileDialogs
Book
ToolBar
ColorPicker
TimePicker
MultiColumnComboBox
SyntaxEditor
VirtualGrid
Wizard
ExpressionEditor
NavigationView (Hamburger Menu)
WatermarkTextBox
DesktopAlert
BarCode
SpellChecker
DataServiceDataSource
EntityFrameworkDataSource
RadialMenu
ChartView3D
Data Virtualization
BreadCrumb
LayoutControl
ProgressBar
Sparkline
TabbedWindow
ToolTip
CloudUpload
ColorEditor
TreeMap and PivotMap
EntityFrameworkCoreDataSource (.Net Core)
HeatMap
Chat (Conversational UI)
VirtualizingWrapPanel
Calculator
NotifyIcon
TaskBoard
TimeSpanPicker
BulletGraph
Licensing
WebCam
CardView
DataBar
FilePathPicker
PasswordBox
SplashScreen
Callout
Rating
Accessibility
CollectionNavigator
Localization
AutoSuggestBox
Security
VirtualKeyboard
HighlightTextBlock
TouchManager
StepProgressBar
Badge
OfficeNavigationBar
ExpressionParser
CircularProgressBar
SvgImage
PipsPager
SlideView
AI Coding Assistant
+? more
Top users last month
Cynthia
Top achievements
Rank 1
Iron
Toby
Top achievements
Rank 3
Iron
Iron
Iron
Danielle
Top achievements
Rank 1
Iron
Iron
Joel
Top achievements
Rank 3
Bronze
Bronze
Iron
yw
Top achievements
Rank 2
Iron
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Cynthia
Top achievements
Rank 1
Iron
Toby
Top achievements
Rank 3
Iron
Iron
Iron
Danielle
Top achievements
Rank 1
Iron
Iron
Joel
Top achievements
Rank 3
Bronze
Bronze
Iron
yw
Top achievements
Rank 2
Iron
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?