<!-- Copyright (C) Microsoft Corporation. All rights reserved. -->
<UIX
  xmlns="http://schemas.microsoft.com/2007/uix"
  xmlns:btn="res://ZuneShellResources!Button.uix"
  xmlns:iris="assembly://UIX/Microsoft.Iris"
  xmlns:style="res://ZuneShellResources!Style.uix"  
  xmlns:styles="res://ZuneShellResources!Styles.uix"
  xmlns:me="Me">

  
  <UI Name="Default">
    <Locals>
      <iris:Choice DefaultIndex="1" Name="FirstModel">
        <Options>
          <String String="Choice 1"/>
          <String String="Choice 2"/>
          <String String="Choice 3"/>
        </Options>
      </iris:Choice>
      <iris:Choice DefaultIndex="2" Name="SecondModel">
        <Options>
          <String String="Choice 1"/>
          <String String="Choice 2"/>
          <String String="Choice 3"/>
        </Options>
      </iris:Choice>
    </Locals>
    <Scripts>
       <Script>
           FirstModel.DefaultValue();
           SecondModel.DefaultValue();
       </Script>
    </Scripts>
    <Content>
      <ColorFill Padding="20" Content="White">
      <Layout>
         <FlowLayout Orientation="Vertical" Spacing="20,20" />
      </Layout>
      <Children>
      <me:RadioGroup Model="{FirstModel}" />
      <me:RadioGroup Model="{SecondModel}" />
      </Children>
      </ColorFill>
    </Content>
  </UI>

  
  <UI Name="MCRadioGroup" Base="me:RadioGroup">
    <Properties>
      <Size Name="ColumnSize" Size="175,0"/>
      <Int32 Name="ColumnCount" Int32="2"/>
      <Size Name="GridSpacing" Size="5,5"/>
    </Properties>

    <Content>
      <Panel Name="RootPanel" Navigation="TabGroup,ContainDirectional,RememberFocus" Layout="VerticalFlow">
        <Children>

          <Repeater Name="Repeater" ContentName="RadioButton">
            <Layout>
              <GridLayout Orientation="{Orientation}" 
                          AllowWrap="true" 
                          ReferenceSize="{ColumnSize}" 
                          Columns="{ColumnCount}" 
                          Spacing="{GridSpacing}"/>
            </Layout>
          </Repeater>

        </Children>
      </Panel>
    </Content>

    <Content Name="RadioButton">
      <me:RadioButton Available="{AvailableChoice}"
                            Model="{Model}"
                            Option="{RepeatedItem}"
                            Visible="{!string.IsNullOrEmpty(((iris:Command)RepeatedItem).Description)}"/>
    </Content>
  </UI>

  
  <UI Name="RadioGroup">
    <Properties>
      <iris:Choice Name="Model" Choice="$Required"/>
      <Orientation Name="Orientation" Orientation="Vertical"/>
      <Boolean Name="Available" Boolean="true"/>
      <String Name="AccessibleDescription" String="{null}"/>
    </Properties>
    <Locals>
      <iris:BooleanChoice Name="AvailableChoice" Value="{Available}" />

      <Accessible Name="Accessible"/>
    </Locals>

    <Scripts>
      <Script>
        AvailableChoice.Value = [Available];
      </Script>
      
      <Script>
        if ([Model] != null)
        {
          Repeater.Source = Model.Options;
         
        }
      </Script>
      
      <Script>
        if (Model != null)
        {
          Repeater.DefaultFocusIndex = [Model.ChosenIndex];
        }
      </Script>

      <Script>
        if ([Accessible.Enabled])
        {
          Accessible.Name = [AccessibleDescription];
          Accessible.Role = AccessibleRole.Grouping;
        }
      </Script>
    </Scripts>
    
    <Content>
      <Panel Name="RootPanel" Navigation="TabGroup,ContainDirectional,RememberFocus">
        <Children>

          <Repeater Name="Repeater" ContentName="RadioButton">
            <Layout>
              <FlowLayout Orientation="{Orientation}" Spacing="5,0" ItemAlignment="Near" AllowWrap="true"/>
            </Layout>
          </Repeater>

        </Children>
      </Panel>
    </Content>

    <Content Name="RadioButton">
      <me:RadioButton Available="{AvailableChoice}" Model="{Model}" Option="{RepeatedItem}"/>
    </Content>
  </UI>

  <UI Name="RadioButton">
    <Properties>
      <iris:Choice Name="Model" Choice="$Required"/>
      <Boolean Name="WordWrap" Boolean="true"/>
      <Object Name="Option" Object="$Required"/>
      <iris:BooleanChoice Name="Available" />

      <Boolean Name="ShowImage" Boolean="true" />
      <Size Name="BoxSize" Size="18,18"/>

      
      <Image Name="BoxFocusImage" Source="res://ZuneShellResources!RadioButtonFocus.png"/>
      <Image Name="BoxNonFocusImage" Source="res://ZuneShellResources!RadioButtonNonFocus.png"/>
      <Image Name="BoxCheckedImage" Source="res://ZuneShellResources!RadioButtonChecked.png"/>
      <Image Name="BoxDisabledImage" Image="res://ZuneShellResources!RadioButtonDisabled.png"/>

      <String Name="AccessibleDescription" String="{null}"/>

      
      <style:Style Name="OverrideStyle" Style="{null}"/>
      <style:Style Name="BaseStyle" Style="{styles:SharedStyles.RadioButtonStyle}"/>
    </Properties>

    <Input>
      
      <ClickHandler Name="Clicker" HandlerStage="Direct,Bubbled" />
    </Input>

    <Locals>
      <style:StatefulCompositeStyle Name="Style" Base="{BaseStyle}"/>
      <Accessible Name="Accessible"/>
    </Locals>

    <Scripts>
      
      <Script>Style.Override = [OverrideStyle];</Script>

      
      <Script>Style.State.Focused = [UI.DeepKeyFocus];</Script>
      <Script>Style.State.Hovered = [UI.DeepMouseFocus];</Script>
      <Script>Style.State.Disabled = ![UI.FullyEnabled];</Script>
      <Script>Style.State.Selected = ([Model.Chosen] == Option);</Script>

      <Script>
        UI.Enabled = [Available.Value];
      </Script>

      <Script>
        if ([UI.DeepKeyFocus])
        {
          Model.Chosen = Option;
        }
      </Script>

      <Script>
        [DeclareTrigger(Clicker.Invoked)]
        Model.Chosen = Option;
      </Script>

      <Script>
        if ([Model.Chosen] == Option)
        {
          Check.Visible = true;
        }
        else
        {
          Check.Visible = false;
        }
      </Script>
      
      <Script>
        if ([Option] is String)
        {
          Label.Content = (String)Option;
        }
        else if (Option is iris:ModelItem)
        {
          Label.Content = ((iris:ModelItem)Option).Description;
        }
      </Script>
      
      
      <Script>
        if ( ![UI.FullyEnabled] )
        {
          Box.Content = BoxDisabledImage;
          Check.Alpha = 0.5;
        }
        else
        {
          Check.Alpha = 1.0;

          if (UI.DeepKeyFocus || UI.DeepMouseFocus)
          {
            Box.Content = BoxFocusImage;
          }
          else
          {
            Box.Content = BoxNonFocusImage;
          }
        }
      </Script>

      <Script>
        if ([UI.FullyEnabled] &amp;&amp; [Clicker.Clicking])
        {
          UI.NavigateInto();
        }
      </Script>

      <Script>
        if ([Accessible.Enabled])
        {
          if (AccessibleDescription != null)
          {
            Accessible.Name = [AccessibleDescription];
          }
          else
          {
            Accessible.Name = [Label.Content];
          }
          
          Accessible.IsChecked = [Check.Visible];
          Accessible.Role = AccessibleRole.RadioButton;
        }
      </Script>
    </Scripts>

    <Content>
      <Panel MouseInteractive="true">
        <Layout>
          <FlowLayout Orientation="Horizontal" ItemAlignment="Center"/>
        </Layout>
        <Children>

          
          <Graphic Name="Box" Visible="{ShowImage}" Content="{BoxNonFocusImage}" MaximumSize="{BoxSize}" Margins="0,0,5,0" Layout="Form">
            <Children>

              
              <Graphic Name="Check" Content="{BoxCheckedImage}">
                <LayoutInput>
                  <FormLayoutInput Left="Parent,0" Top="Parent,0"/>
                </LayoutInput>
              </Graphic>

            </Children>
          </Graphic>
          
          
          <btn:Label Name="Label" Style="{Style}" WordWrap="{WordWrap}" />

        </Children>
      </Panel>
    </Content>
  </UI>

</UIX>
