2013-01-18 3 views
4

나는 이것을 작동 시키는데 어려움을 겪고 있습니다. 이 코드는 MVVM 앱에 있으며 ViewModel의 속성에 라디오 버튼을 바인딩합니다. ListBox에있는 가로형 라디오 버튼

나는이 SO https://stackoverflow.com/a/2285732

모든이 버튼이 수직으로 적층되는 것을 제외하고는 잘 작동 답변을 구현하기 위해 노력하고있어. 자, 이것은 쉬운 수정, 그냥 ItemsPanelTemplate 수정 보인다.

<ListBox ItemsSource="{Binding ItemOptions}" SelectedItem="{Binding SelectedOption}"> 
    <ListBox.ItemsPanel> 
      <ItemsPanelTemplate> 
       <StackPanel Orientation="Horizontal" IsItemsHost="True" /> 
      </ItemsPanelTemplate> 
    </ListBox.ItemsPanel> 
    <ListBox.ItemContainerStyle> 
      <Style TargetType="{x:Type ListBoxItem}"> 
       <Setter Property="Template"> 
        <Setter.Value> 
         <ControlTemplate TargetType="{x:Type ListBoxItem}" > 
          <RadioButton Content="{TemplateBinding Content}" 
           IsChecked="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=IsSelected}"/> 
         </ControlTemplate> 
        </Setter.Value> 
       </Setter> 
      </Style> 
    </ListBox.ItemContainerStyle> 
</ListBox> 

그러나, 항목이 수직으로 적층 된 상태로 유지 :

여기 내 코드입니다. 이것이 ListBox의 방향에 아무런 영향을 미치지 않는 이유는 무엇입니까? 내가 뭘 놓치고 있니?

감사합니다, 제리

+0

XAML과 F5를 복사하여 붙여 넣기 만하면됩니다. 항목은 가로로 쌓입니다. 어떤 .Net 버전을 사용하고 있습니까? –

+0

대상 지정 .NET 4.0 –

+0

그렇다면 이해할 수 없습니다 ... 또한 4.0을 사용하고 있으며 정확한 XAML이 내 PC에서 잘 작동합니다 .... –

답변

2

이 시도 : 당신이했던 것처럼

  <ListBox.Template> 
       <ControlTemplate TargetType="{x:Type ListBox}"> 
         <ScrollViewer x:Name="scrollviewer" HorizontalScrollBarVisibility="Visible" CanContentScroll="False"> 
         <StackPanel IsItemsHost="True" Orientation="Horizontal" /> 
         </ScrollViewer> 
       </ControlTemplate> 
      </ListBox.Template> 

내가 성공하지 않고, 이것을 ItemsPanelTemplate 작업을 얻기 위해 노력했다. 이것은 나를 위해 위대한 일을했다, 그것은 당신도 도움이되기를 바랍니다!

감사합니다.

+0

네 - 그거야. 빠른 도움에 감사드립니다. –

관련 문제