Click here to Skip to main content
11,571,102 members (69,278 online)
Rate this: bad
good
Please Sign up or sign in to vote.
With following code I add available serial port names to the RibbonGallery object:
xaml:
<ribbon:RibbonComboBox Name="cmbBoxComPortName" SelectionBoxWidth="40" Label="Port name:">
    <ribbon:RibbonGallery Name="galleryComPortName" SelectionChanged="galleryComPortName_SelectionChanged" />
</ribbon:RibbonComboBox>
code-behind c#:
galleryComPortName.ItemsSource = SerialPortAdapter.GetAvailablePortList();

SerialPortAdapter code:
class SerialPortAdapter
{
    public static List<string> GetAvailablePortList()
    {
        var portList = SerialPort.GetPortNames().ToList();
        portList.Sort();
        return portList;
    }
}

The problem is now, that the port names are present in the combobox but they are not selectable.

How can I select them and treat the event to set my port name?
Posted 20-Sep-12 22:16pm
Edited 21-Sep-12 0:29am
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I had the same problem with Ribbon:RibbonComboBox controller. Is your project .Net 3.5? That might be causing my problems.

My workaround was to use the original ComboBox controller instead of Ribbon:RibbonComboBox.
  Permalink  
Comments
llf77 at 21-Sep-12 4:58am
   
My target framework is .Net 4 Client Profile.
Thanks the original ComboBox works´. But I was hopping to get a solution for the ribbons.
theaob at 21-Sep-12 7:00am
   
Have a look at this post: http://blogs.msdn.com/b/llobo/archive/2010/08/19/using-ribbongallery-control.aspx
I think you should add every Com port name as a gallery item
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Sorry this, isn't a solution. Don't know a way to add more code after the previous answers.

Now I tried following, but unfortunatelly with the the same result.

Code in SerialPortAdapter:

public static ObservableCollection<RibbonGalleryItem> GetAvailablePortList()
{
    var portList = SerialPort.GetPortNames().ToList();
    portList.Sort();
 
    var portObsCol = new ObservableCollection<RibbonGalleryItem>();
    foreach (var rgi in portList.Select(port => new RibbonGalleryItem() { Content = port, Name = port }))
    {
        portObsCol.Add(rgi);
    }
 
    return portObsCol;
}
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Found out this way, which is working.

xaml:
<ribbon:RibbonComboBox Name="cmbBoxComPortNameRibbon" SelectionBoxWidth="40" Label="Port name:">
    <ribbon:RibbonGallery Name="galleryComPortName" SelectionChanged="GalleryComPortNameSelectionChanged" SelectedValuePath="Content">
        <ribbon:RibbonGalleryCategory Name="galleryCategoryComPortName"/>
    </ribbon:RibbonGallery>
</ribbon:RibbonComboBox>

code-behind C#:
galleryCategoryComPortName.ItemsSource = SerialPortAdapter.GetAvailablePortList();

SerialPortAdapter code:
public static ObservableCollection<RibbonGalleryItem> GetAvailablePortList()
{
    var portList = SerialPort.GetPortNames().ToList();
    portList.Sort();
 
    var portObsCol = new ObservableCollection<RibbonGalleryItem>();
    foreach (var rgi in portList.Select(port => new RibbonGalleryItem() { Content = port, Name = port }))
    {
        portObsCol.Add(rgi);
    }
 
    return portObsCol;
}
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


Advertise | Privacy | Mobile
Web04 | 2.8.150624.2 | Last Updated 24 Sep 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100