Telerik Forums
UI for WPF Forum
1 answer
402 views
I came across the need to be able to sort my ObservableCollections the other day and I found a nice code snippet demonstrating how to sort an ObservableCollection even if the collection type does not support IComparable. I added the ReverseCompare/Descending sort just in case. Anyhow thought it was a neat piece of code and hope it may help some others out there.

Enjoy!

public static class CollectionSorter  
    {  
        public static void Sort<T>(this ObservableCollection<T> collection, Comparison<T> comparison)  
        {  
            var comparer = new Comparer<T>(comparison);  
 
            List<T> sorted = collection.OrderBy(x => x, comparer).ToList();  
 
            for (int i = 0; i < sorted.Count(); i++)  
                collection.Move(collection.IndexOf(sorted[i]), i);  
        }  
 
        public static void DescendingSort<T>(this ObservableCollection<T> collection, Comparison<T> comparison)  
        {  
            var comparer = new ReverseComparer<T>(comparison);  
 
            List<T> sorted = collection.OrderBy(x => x, comparer).ToList();  
 
            for (int i = 0; i < sorted.Count(); i++)  
                collection.Move(collection.IndexOf(sorted[i]), i);  
        }       
    }  
 
    internal class Comparer<T> : IComparer<T>  
    {  
        private readonly Comparison<T> comparison;  
 
        public Comparer(Comparison<T> comparison)  
        {  
            this.comparison = comparison;  
        }
        #region IComparer<T> Members  
 
        public int Compare(T x, T y)  
        {  
            return comparison.Invoke(x, y);  
        }
        #endregion  
    }  
 
    internal class ReverseComparer<T> : IComparer<T>  
    {  
        private readonly Comparison<T> comparison;  
 
        public ReverseComparer(Comparison<T> comparison)  
        {  
            this.comparison = comparison;  
        }
        #region IComparer<T> Members  
 
        public int Compare(T x, T y)  
        {  
            return -comparison.Invoke(x, y);  
        }
        #endregion  
    } 

then you can use it on your ObservableCollections as such. 
private void Log(LogEntry log)  
        {  
            LoggedEvents.Add(log);  
            LoggedEvents.DescendingSort((x, y) => x.TimeStampString.CompareTo(y.TimeStampString));  
        }        
 
        private ObservableCollection<LogEntry> entries = new ObservableCollection<LogEntry>();  
        public ObservableCollection<LogEntry> LoggedEvents  
        {  
            get 
            {                  
                return entries;  
            }  
            set 
            {  
                entries = value;  
                RaisePropertyChanged(LoggedProperty);  
            }  
        } 
Jonas
Top achievements
Rank 1
 answered on 27 Nov 2012
1 answer
215 views
How to disable row edit mode? Leave only insert and delete.
Yoan
Telerik team
 answered on 27 Nov 2012
1 answer
231 views
Hi,

If the vertical scrollbar is used to scroll the list of dropdown items and then whilst the drop down is still displayed the applications main window is moved, the dropdown panel remains at it's former position and does not follow the location of the autocomplete edit box.

Is there a way to control this so that it either moves with the form or closes before the form is moved in the same way that a combobox would?

Attached screenshot illustrates the problem when using the WPF demo controls application.

Rgds
Graeme
Alek
Telerik team
 answered on 27 Nov 2012
0 answers
65 views
HI ,

i am using trail version of Test studio and i want to display the value of a variable. To display the value in C# we will use "MessageBox.Show("Value of the variable")". when i use this method i am getting one error message as namespace is not added as a hedder files, but i am not able to see in the list namesapces because i have not added repective *.dll files. can any one please let me know about adding of *.dll files.

Thanks
satyanarayana
S
Top achievements
Rank 1
 asked on 27 Nov 2012
2 answers
223 views
Hello,

We are using version 2012.2.607.40 of your WPF controls.  Our application supports several font sizes so we updated many Telerik styles and templates for the PropertyGrid to use the dynamic font size. Our changes worked for the property names (they all show the correct size now), but some of the values do not.  We do not see where the value templates are so that we can change them.

How can we get to the right templates for the PropertyGrid values so we can change them to use our dynamic size -for all the value types used in the property grid? Or, is there another way to accomplish this?  I've attached a picture so you can visualize the problem.  You can see some of the values have the larger size but others do not. 

Thanks!
-Mark
mark
Top achievements
Rank 1
 answered on 27 Nov 2012
2 answers
141 views
When I run my program with debug then everything works normal, but whenever I run without debug or from the exe it dosn't display anything.  Actually it tells me it is empty when I have already added the controls in xaml, they are static not dynamic at all.  It still says all my controls exist and I can use them but they not displayed at all.  This used to work but I made not changes that would break it.  I do however toggle it's visibility but even when I have it always visible it dosn't work.  It's like it is not seeing anything under the RadDocking tag.

<telerik:RadDocking Background="#edf3fa"  x:Name="dmManager" Grid.Row="1" Margin="0,0,0,33" Padding="0,0,0,0">
            <telerik:RadDocking.DocumentHost>
                <telerik:RadSplitContainer>
                    <telerik:RadPaneGroup>
                    (Assume controls)
                    </telerik:RadPaneGroup>
                </telerik:RadSplitContainer>
            </telerik:RadDocking.DocumentHost>
 
            <telerik:RadSplitContainer InitialPosition="DockedLeft">
                <telerik:RadPaneGroup>
                    (Assume controls)
                </telerik:RadPaneGroup>
            </telerik:RadSplitContainer>
 
            <telerik:RadSplitContainer InitialPosition="DockedRight">
                <telerik:RadPaneGroup>
                    (Assume controls)
                </telerik:RadPaneGroup>
            </telerik:RadSplitContainer>
 
            <telerik:RadSplitContainer x:Name="Bottom"  InitialPosition="DockedBottom">
                <telerik:RadPaneGroup>
                    (Assume controls)
                </telerik:RadPaneGroup>
            </telerik:RadSplitContainer>
        </telerik:RadDocking>
Alex
Top achievements
Rank 1
 answered on 26 Nov 2012
1 answer
248 views
What is the proper way of coding standard to bind the ObservableCollection to ItemSource?
The case i'm facing is i have multiple lineseries, therefore, i created an ObservableCollection<IEnumberable><T>> that contains array of ObservableCollection<T>. i make the ObservableCollection<IEnumberable><T>> binded to the itemsource of lineSeries with INotifyPropertyChanged.

Code Snippet:
XAML:
<chartView:LineSeries x:Name="Item1" ItemsSource="{Binding Item[0]}" ValueBinding="Value" CategoryBinding="Counter" />
<chartView:LineSeries x:Name="Item2" ItemsSource="{Binding Item[1]}" ValueBinding="Value" CategoryBinding="Counter" />
<chartView:LineSeries x:Name="Item3" ItemsSource="{Binding Item[2]}" ValueBinding="Value" CategoryBinding="Counter" />
<chartView:LineSeries x:Name="Item4" ItemsSource="{Binding Item[3]}" ValueBinding="Value" CategoryBinding="Counter" />
<chartView:LineSeries x:Name="Item5" ItemsSource="{Binding Item[4]}" ValueBinding="Value" CategoryBinding="Counter" />

C#
public ObservableCollection<IEnumerable<GraphPlot>> Item
{
      get { return m_item; }
      set
      {
           m_item = value;
           OnPropertyChanged("Item");
      }
}

i have an error "observablecollection collection was modified enumeration operation may not execute" using the code above.
is this the right way to bind it to multiple itemsource with only 1 Properties at real-time? any recommendation?

Petar Kirov
Telerik team
 answered on 26 Nov 2012
1 answer
221 views
<Rectangle Stroke="Black" StrokeThickness="1" Fill="#DADADA" Height="8" Width="8">
     <Rectangle.Triggers>
       <EventTrigger RoutedEvent="MouseLeftButtonDown">
         <BeginStoryboard>
           <Storyboard>
             <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="IsOpen" Storyboard.Target="{x:Reference ContextMenu}">
               <DiscreteObjectKeyFrame>
                 <DiscreteObjectKeyFrame.Value>
                   <sys:Boolean>True</sys:Boolean>
                 </DiscreteObjectKeyFrame.Value>
               </DiscreteObjectKeyFrame>
             </ObjectAnimationUsingKeyFrames>
           </Storyboard>
         </BeginStoryboard>
       </EventTrigger>
     </Rectangle.Triggers>
     <telerik:RadContextMenu.ContextMenu>
       <telerik:RadContextMenu x:Name="ContextMenu" ShowDelay="0">
         <telerik:RadMenuItem Header="Reset value" />
         <telerik:RadMenuItem Header="Set binding" />
       </telerik:RadContextMenu>
     </telerik:RadContextMenu.ContextMenu>
   </Rectangle>

Click on the rectangle, then click somewhere else and radcontextmenu stays opened.  This way you can open multiple contexmenus simultaneously

This does not happen with regular contextmenu.
Rosen Vladimirov
Telerik team
 answered on 26 Nov 2012
3 answers
244 views
Hello,

I bind 2 Controls

<telerik:RadToggleButton x:Name="ShowLogButton"  Grid.Column="1" Grid.Row="1" Content="..."></telerik:RadToggleButton>
<telerik:RadListBox ItemsSource="{Binding Path=Log}" DisplayMemberPath="Description" Grid.Column="0" Grid.Row="2" Grid.ColumnSpan="2" Height="70" Visibility="{Binding ElementName=ShowLogButton, Path=IsChecked,  Converter={StaticResource ControlVisibilityConverter}}">
</telerik:RadListBox>

Follow Visible attribute, after saving and loading my window with Persistence Framework my toggle button is broken and dont works anymore

This code helps

<telerik:RadToggleButton x:Name="ShowLogButton"  Grid.Column="1" Grid.Row="1" Content="..."></telerik:RadToggleButton>
<telerik:RadListBox ItemsSource="{Binding Path=Log}" DisplayMemberPath="Description" Grid.Column="0" Grid.Row="2" Grid.ColumnSpan="2" Height="70" Visibility="{Binding ElementName=ShowLogButton, Path=IsChecked,  Converter={StaticResource ControlVisibilityConverter}}">
<telerik:PersistenceManager.SerializationOptions>
    <telerik:SerializationMetadataCollection>
        <telerik:PropertyNameMetadata Condition="Except" Expression="Visibility" SearchType="PropertyName" />
    </telerik:SerializationMetadataCollection>
</telerik:PersistenceManager.SerializationOptions>
</
telerik:RadListBox>

Should i use this for every binded Porperty? Can i exclude any binded properties from serialisation ?
Tina Stancheva
Telerik team
 answered on 26 Nov 2012
1 answer
200 views
Hi,

I've noticed that the panes and floating windows aren't focused when I right mouse click on each control.

What's the best way to focus a Pane/Floating Window on right mouse click?

Thank you for your time,

Rob
Georgi
Telerik team
 answered on 26 Nov 2012
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?