locked
How do I build my own XAML Object?

    Question

  • I am at an impasse with my current development. While I am a very experienced developer, I am having a great deal of trouble acclimating to Windows 8. I actually have two questions (one general) and one specific ... but I will ask the general question on another thread (question: Can I develop for windows 8 using C# and .NET, but NOT through the windows store? Personally, I find the Windows 8 Store App technology to be very limiting and not very useful. It is still a target of ours, but would prefer the ability to make quick and dirty applications that do not have to go through the Store and be limited by the Store App framework constraints).

    My main question is, How do you build your own XAML object? Our current problem lies in the use of Radio Buttons. Our client has a great deal of Pass/Fail, Yes/No checks that must be made. However, I cannot bind to the radio buttons (as a group), as they no longer have the concept of a RadioButtonList which took a single value and applied it to the group. Instead, each Radio Button is individually considered.

    I have attempted to use the Radio Buttons inside of a ListBox control, but I run into two problems: 1. The value of the selected RadioButton does not appear to bubble up to the ListBox control;  2. I cannot force the display of the ListBox control to be in a Horizontal Orientation. It looks as though you can do that in Silverlight and WPF, but apparently not in the Store App Framework (that I have found).

    My Code is as follows (if you see any misspellings or missing notations, please ignore them as it is me not transcribing the code properly. I assure you the below code as I have it compiles and displays and interacts, it simply does not provide me with the selected radio button, nor can I get it to display the radio buttons in a horizontal fashion):

    <StackPanel Margin="70,445,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Orientation="Horizontal" Width="120">
    <ListBox x:Name="GaugeRadioButtonList">
    <ListBoxItem IsSelected="{Binding Gauge, ElementName=GaugeRadioButton1, Mode=TwoWay}">
    <RadioButton x:Name="GaugeRadioButton1" GroupName="GaugeGroup">Pass</RadioButton>
    </ListBoxItem>
    <ListBoxItem IsSelected="{Binding Gauge, ElementName=GaugeRadioButton2, Mode=TwoWay}">
    <RadioButton x:Name="GaugeRadioButton2" GroupName="GaugeGroup">Fail</RadioButton>
    </ListBoxItem>
    </ListBox>
    </StackPanel>

    I would like to take the above element and either get it to work properly, or create my own type of RadioButtonList where I can have a series of RadioButtons and a single value, and bind it.

    Any help, hints, or links to other similar questions with answers would be greatly appreciated!!

    Wednesday, October 23, 2013 5:07 PM

Answers

  • Hi Danny,

    Welcome to MSDN forum and I'd like to provide you some information that may help with your developing.

    For your two questions:

    1,  The value of the selected RadioButton does not appear to bubble up to the ListBox control;

    -> Try with following code, change the binding option from "Gauge" to "IsChecked" since radio button does not have the property of Gauge, I'm not sure if this is what you need:

            <StackPanel Margin="70,445,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Orientation="Horizontal" Width="120">
                <ListBox x:Name="GaugeRadioButtonList">
                    <ListBoxItem IsSelected="{Binding IsChecked, ElementName=GaugeRadioButton1, Mode=TwoWay}">
                        <RadioButton x:Name="GaugeRadioButton1" GroupName="GaugeGroup">Pass</RadioButton>
                    </ListBoxItem>
                    <ListBoxItem IsSelected="{Binding IsChecked, ElementName=GaugeRadioButton2, Mode=TwoWay}">
                        <RadioButton x:Name="GaugeRadioButton2" GroupName="GaugeGroup">Fail</RadioButton>
                    </ListBoxItem>
                </ListBox>
            </StackPanel>

    2,  I cannot force the display of the ListBox control to be in a Horizontal Orientation. It looks as though you can do that in Silverlight and WPF, but apparently not in the Store App Framework (that I have found).

    ->I think you can, by setting the style of the listbox, see the screenshot I post, I think this is what you mean by horizontal orientation. You could add following code in your XAML page:

        <Page.Resources>
            <Style TargetType="ListBox">
                <Setter Property="ItemsPanel">
                    <Setter.Value>
                        <ItemsPanelTemplate>
                            <StackPanel Orientation="Horizontal"
                          VerticalAlignment="Center"
                          HorizontalAlignment="Center"/>
                        </ItemsPanelTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
    
        </Page.Resources>

    Hope this can help you. Besides, to develop a user control seems to be a good solution for you, see here UserControl class for more information.

    Best Regards,

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.


    Friday, October 25, 2013 5:29 AM
    Moderator