Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
With following code I add available serial port names to the RibbonGallery object:
xaml:
XML
<ribbon:RibbonComboBox Name="cmbBoxComPortName" SelectionBoxWidth="40" Label="Port name:">
    <ribbon:RibbonGallery Name="galleryComPortName" SelectionChanged="galleryComPortName_SelectionChanged" />
</ribbon:RibbonComboBox>

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


SerialPortAdapter code:
C#
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
Updated 21-Sep-12 0:29am
v3

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.
 
Share this answer
 
Comments
Alfred Loeffler 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 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
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:

C#
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;
}
 
Share this answer
 
v2
Found out this way, which is working.

xaml:
XML
<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#:
C#
galleryCategoryComPortName.ItemsSource = SerialPortAdapter.GetAvailablePortList();


SerialPortAdapter code:
C#
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;
}
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900