SplitComboBox and the ShowCustomValueOption

Feb 1, 2011 at 10:10 AM

Hello!

Could anyone help me to understand using of the SplitComboBox? I would like to create user choosable list, and in case if the result dose not content the requested value, the user able to give it in the custom input filed. I would like similar solution than the Duration on the  detail view of SearchPrescription example.

I saw the source code of the sample, but I cant reproduce the using...

 Any experience or advice?

 public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            this.DataContext = this;
        }

        string[] _pSource = new string[] { "p1", "p2", "p3", "p4" };
        string[] _oSource = new string[] { "o1", "o2", "o3", "o4" };

        public string[] PSource
        {
            get
            {
                return _pSource;
            }
        }

        public string[] OSource
        {
            get
            {
                return _oSource;
            }
        }

        string _pItem;
        string _cItem;

        public string PItem
        {
            get
            {
                return _pItem;
            }
            set
            {
                _pItem = value;
            }
        }

        public string CItem
        {
            get
            {
                return _cItem;
            }
            set
            {
                _cItem = value;
            }
        }

And the XAML:

 

<UserControl x:Class="TestSilverlightApplication.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:Cui_Controls="clr-namespace:Microsoft.Cui.Controls;assembly=Microsoft.Cui.Controls"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400" 
    >

    <UserControl.Resources>
        <DataTemplate x:Key="PTemplate">
            <StackPanel>
                <TextBlock Text="A: "/>
                <TextBlock Text="{Binding}" />
            </StackPanel>
        </DataTemplate>

        <DataTemplate x:Key="CTemplate">
            <StackPanel Orientation="Horizontal">                
                    <TextBlock Text="B: "/>
                    <Cui_Controls:WatermarkedTextBox Watermark="Enter a reason for prescribing" Text="{Binding}" MinWidth="200"
                        TextWrapping="Wrap" MaxWidth="350" MaxLength="128"
                        Cui_Controls:SplitComboBox.CustomValueControlFocusContainer="{Binding RelativeSource={RelativeSource TemplatedParent}}"
                        Margin="-4,-4,15,-4"/>
            </StackPanel>
        </DataTemplate>       
    </UserControl.Resources>
    
    <Grid x:Name="LayoutRoot" Background="White">
        <Cui_Controls:CollapsibleContentControl>
            <Cui_Controls:SplitComboBox x:Name="ConciseDoseList"
                                        MaxHeight="200"
                                        Watermark="Select a site"
                                        ItemTemplate="{StaticResource PTemplate}"                                                           
                                        PrimaryItemsSource="{Binding Path=PSource}"
                                           
                                        ShowCustomValueOption="True"
                                        CustomValueItemTemplate="{StaticResource CTemplate}"
                                        CustomValueItem="{Binding Path=CItem}"
                                       
                                        ConfirmedSelectedItem="{Binding Mode=TwoWay, Path=PItem}"

                                      
                                        Margin="15,0,0,15"
                                        AutomationProperties.Name="Routes"
                                        AlwaysTopAlignDropDown="True"
                                            
                                        MaxWidth="200"
                                        />
        </Cui_Controls:CollapsibleContentControl>
    </Grid>
</UserControl>

Thanks!

 

fjosika

Feb 18, 2011 at 2:06 PM

Solved :), the properis initialization order is very ipmortant: bug

in the SplitItemsControlHelper public static void UpdateItemsSource(ISplitItemsControl splitItemsControl) does not run every time when it needed.

have nice day!