如何在Windows UWP中爲分段控制創建自定義的渲染器。我跟着這個link自定義渲染在IOS和Android的分段控制。但我找不到任何Windows UWP。任何人都可以提供任何資源,或者是否有任何其他方式做到這一點,類似於Windows UWP中的分段控制。Xamarin:用於Windows的分段控制uwp
回答
。
我最近發現了nuget包FreshEssentials。它具有分段按鈕組的實現。按照這個github link找到實現。它很容易使用。
我自定義風格的單選按鈕做了一次。爲您的按鈕編輯RadioButton樣式 - 創建正在查看的已選中和未選中樣式,併爲其分配相同的組,以便當時只能選擇一個按鈕。 不知道有沒有更簡單的方法。
編輯:SAMPE代碼,編輯您想要的方式:我找到了解決自己
<Page.Resources>
<Style x:Key="RadioButtonStyle1" TargetType="RadioButton">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Foreground" Value="{ThemeResource RadioButtonContentForegroundThemeBrush}"/>
<Setter Property="Padding" Value="0,0,0,0"/>
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="VerticalAlignment" Value="Stretch"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}"/>
<Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="RadioButton">
<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal"/>
<VisualState x:Name="PointerOver">
</VisualState>
<VisualState x:Name="Pressed">
</VisualState>
<VisualState x:Name="Disabled">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="BackgroundRectangle">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource RadioButtonDisabledBackgroundThemeBrush}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentPresenter">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource RadioButtonContentDisabledForegroundThemeBrush}"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
<VisualStateGroup x:Name="CheckStates">
<VisualState x:Name="Checked">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="BackgroundRectangle">
<DiscreteObjectKeyFrame KeyTime="0" Value="Blue"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentPresenter">
<DiscreteObjectKeyFrame KeyTime="0" Value="White"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Unchecked">
</VisualState>
<VisualState x:Name="Indeterminate"/>
</VisualStateGroup>
<VisualStateGroup x:Name="FocusStates">
<VisualState x:Name="Focused">
<Storyboard>
<DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="FocusVisualWhite"/>
<DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="FocusVisualBlack"/>
</Storyboard>
</VisualState>
<VisualState x:Name="Unfocused"/>
<VisualState x:Name="PointerFocused"/>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Grid HorizontalAlignment="Stretch">
<Grid x:Name="BackgroundRectangle" Background="Transparent">
<Border BorderThickness="1" BorderBrush="White" Margin="0" HorizontalAlignment="Stretch">
<Rectangle Margin="0" StrokeThickness="{ThemeResource RadioButtonBorderThemeThickness}" HorizontalAlignment="Stretch" UseLayoutRounding="False"/>
</Border>
<TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" x:Name="Title"></TextBlock>
</Grid>
<ContentPresenter x:Name="ContentPresenter" Foreground="White" AutomationProperties.AccessibilityView="Raw"
ContentTemplate="{TemplateBinding ContentTemplate}" ContentTransitions="{TemplateBinding ContentTransitions}"
Content="{TemplateBinding Content}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Page.Resources>
<Grid Height="40" Background="Black" BorderThickness="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="10"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="10"/>
</Grid.ColumnDefinitions>
<RadioButton Height="30" Content="Button1" Grid.Column="1" Style="{StaticResource RadioButtonStyle1}" GroupName="MainGroup" Checked="Button1_OnChecked"></RadioButton>
<RadioButton Height="30" Content="Button2" Grid.Column="2" Style="{StaticResource RadioButtonStyle1}" GroupName="MainGroup" Checked="Button2_OnChecked"></RadioButton>
<RadioButton Height="30" Content="Button3" Grid.Column="3" Style="{StaticResource RadioButtonStyle1}" GroupName="MainGroup" Checked="Button3_OnChecked"></RadioButton>
<RadioButton Height="30" Content="Button4" Grid.Column="4" Style="{StaticResource RadioButtonStyle1}" GroupName="MainGroup" Checked="Button4_OnChecked"></RadioButton>
</Grid>
能否請您對UWP定製提供一些代碼。是的,它可以用單選按鈕來完成,但不確定在這種情況下uwp中使用的佈局模板。 –
在樣式開始的行下添加了樣本代碼 – RTDev
的編輯,您可以看到一些
- 1. Xamarin按行分開控制
- 2. 使用Xamarin控制UWP應用程序(Android)
- 3. Xamarin Forms UWP PageRenderer
- 4. 使用UWP windows mobile禁用Xamarin Forms上的UI虛擬化10
- 5. C#Windows窗體:用於製表控制
- 6. 適用於Windows IOT的SQLite控制檯
- 7. 採用分段控制切換的tableView
- 8. Windows UWP開發問題(Windows 10模擬器和Xamarin)
- 9. Xamarin,UWP和依賴
- 10. 如何區分段控制中的段?
- 11. 滾動對廣告的控制 - 的Windows Phone UWP
- 12. UWP上的Xamarin MasterDetailPage菜單
- 13. Windows 10中的背景控制UWP不會模糊
- 14. 通過分段控制
- 15. iOS分段控制問題
- 16. 分段控制導航欄
- 17. iphone分段控制和uitableview
- 18. ScrollViews和分段控制器
- 19. Xamarin Forms:用於UWP和win8.1的自定義progressbar渲染器
- 20. 帶SQlite的Xamarin(iOS Android UWP)使用OneToMany
- 21. 分段控制輸入Android應用
- 22. 使用分段控制Swift 3
- 23. 在UWP中禁用焦點控制
- 24. 在WPF控制 - 顯示UWP應用
- 25. Xamarin UWP應用程序不起作用
- 26. 分段控制差分按鈕
- 27. Xamarin UWP品牌工具欄
- 28. 的Windows UWP使用RichTextEditor
- 29. 使用UWP的OCR(Windows 10)
- 30. 按分段標題推送到分段控制段
Asesome @Himanshu(y)! –
還有這個:(https://github.com/1iveowl/Plugin.SegmentedControl –