Silverlight中是否存在多状态切换按钮?我试图在一个组中重新尝试模拟单选按钮,但是我想制作一个跨切换状态的故事板,并且因为单选按钮是单独的对象,我被卡住了(我试图让它看起来像是iPhone的切换器按钮,除了多态)Silverlight多状态切换按钮
1
A
回答
0
标准的Silverlight CheckBox
作为IsThreeState
财产。第三种状态的默认视觉效果是“ - ”,因此您可能需要自定义视觉效果。
CheckBox是ToggleButton的一个特例。
0
你可能知道OOTB CheckBox控件:
这可能是有用的,但我的项目之一,它必须是类似的功能,但使用的输入而是使用自定义的UserControl方法。我强烈推荐它。
在用户控件的构造函数中,InitializeComponent();之后;您可以指定影响UI的值。时间允许我会注释一些xaml + cs。
下面是一些代码:
XAML:
<UserControl x:Class="SilverlightApplication1.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"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<Grid x:Name="LayoutRoot" Background="White">
<Grid.Resources>
<Style x:Key="TernaryTB" TargetType="TextBox">
<Setter Property="HorizontalAlignment" Value="Left"/>
<Setter Property="VerticalAlignment" Value="Top"/>
<Setter Property="Width" Value="64"/>
<Setter Property="Height" Value="39"/>
<Setter Property="FontWeight" Value="ExtraBold"/>
<Setter Property="FontFamily" Value="Portable User Interface"/>
<Setter Property="FontSize" Value="18"/>
<Setter Property="TextAlignment" Value="Center" />
</Style>
</Grid.Resources>
<TextBox x:Name="BackgroundTextBox" IsEnabled="True" BorderBrush="White" Foreground="{x:Null}" Visibility="Visible" Style="{StaticResource TernaryTB}"/>
<TextBox x:Name="TernaryTextBox" Style="{StaticResource TernaryTB}" GotFocus="TernaryTextBox_GotFocus"/>
</Grid>
</UserControl>
CS:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
namespace SilverlightApplication1
{
public partial class MainPage : UserControl
{
private int current;
public int Current
{
get
{
return current;
}
set
{
current = value;
}
}
public struct DataStructure
{
private string label;
private Color color;
private Color forecolor;
public DataStructure(string label, Color c, Color c2)
{
this.label = label;
this.color = c;
this.forecolor = c2;
}
public string Label
{
get { return label; }
set { label = value; }
}
public Color Color
{
get { return color; }
set { color = value; }
}
public Color Forecolor
{
get { return forecolor; }
set { forecolor = value; }
}
}
IList<DataStructure> DataStructureArray;
public MainPage()
{
InitializeComponent();
current = 0;
int i = 0;
DataStructureArray = new Collection<DataStructure>
(new[] {
new DataStructure ("A", Colors.Red,Colors.Green),
new DataStructure ("B", Colors.Green,Colors.Blue),
new DataStructure ("C", Colors.Blue,Colors.Red)
});
foreach (DataStructure listItem in DataStructureArray)
{
if (i == current)
{
TernaryTextBox.Text = listItem.Label;
TernaryTextBox.Background = new SolidColorBrush(listItem.Color);
break;
}
i++;
}
}
public MainPage(IList<DataStructure> NewDataStructureArray)
{
int i = 0;
DataStructureArray = new Collection<DataStructure>();
foreach (DataStructure ds in NewDataStructureArray)
{
DataStructureArray.Add(new DataStructure(ds.Label, ds.Color, ds.Forecolor));
i++;
}
}
private void TernaryTextBox_GotFocus(object sender, RoutedEventArgs e)
{
int i = 0;
current = (current + 1) % 3;
foreach (DataStructure listItem in DataStructureArray)
{
if (i == current)
{
TernaryTextBox.Text = listItem.Label;
TernaryTextBox.Background = new SolidColorBrush(listItem.Color);
TernaryTextBox.Foreground = new SolidColorBrush(listItem.Forecolor);
BackgroundTextBox.Focus();
break;
}
i++;
}
BackgroundTextBox.Focus();
}
}
}
要测试,只需一个品牌打屁股用户控件添加到项目中,复制粘贴我的代码;来测试我的孤立的代码,打开App.xaml.cs并只需更换:
this.RootVisual = new MainPage();
有:
this.RootVisual = new <Whatevernameyouchosefortheusercontrol>();
看到它在行动
相关问题
- 1. Silverlight按钮切换按钮时背景图像更改状态
- 2. 切换按钮状态
- 3. 3状态切换按钮?
- 4. Android切换按钮状态
- 5. Android多状态切换按钮检查状态
- 6. 管理切换按钮的状态
- 7. 切换按钮更改其状态
- 8. 恢复在ionic2切换按钮状态
- 9. Arduino的按钮状态切换
- 10. 切换按钮状态并重用其他按钮的切换功能
- 11. 自定义wpf中的切换按钮的切换状态
- 12. Ionic2切换切换按钮状态基于方法
- 13. 按钮不是从禁用状态切换到启用状态
- 14. 更改切换按钮/单选按钮状态外部事件
- 15. Android的多状态切换
- 16. jQuery多状态切换
- 17. 将按钮从默认状态切换到按下状态并返回
- 18. UIBarButtonItem。如果按钮被按下,如何显示切换状态?
- 19. Silverlight中的三个状态按钮
- 20. 切换按钮不切换
- 21. 切换按钮
- 22. UIBarButtonItem正常和按下状态切换?
- 23. 如何切换按钮的选中状态和CheckBox
- 24. VBA Excel,更改ActiveX切换按钮的状态
- 25. 如何更改切换按钮的状态?
- 26. 单选按钮不会切换其状态
- 27. 在Android中更改切换按钮状态的问题
- 28. Android的变化切换按钮状态 - TextView的或其他android.widget
- 29. 删除切换按钮backgroung在激活状态
- 30. 切换取决于按钮状态的函数?
谢谢。我会考虑这个 – Aks