我正在努力让这个在我正在研究的WPF应用程序中工作.基本上,我所追求的是像MMC中的任务窗格:
我试图在XAML和绑定中尽可能多地做.
我能为它加上奶油,冰淇淋和巧克力片吗?:-)
我指的是蓝色ON/OFF样式,如ICS手机上的默认Android设置应用程序所示.它也可以在这里看到:http://android-developers.blogspot.com/2012/02/android-design-v2-now-with-stencils.html 我想将它们放在Preference屏幕中,我是否必须使用自定义首选项小部件?
此外,在操作栏中放置切换按钮是否容易?这似乎是可能的,因为它是在ICS的默认Android设置中为Wifi设置完成的,但它可能是一个自定义菜单项?
任何帮助是极大的赞赏.
android togglebutton android-preferences android-4.0-ice-cream-sandwich android-actionbar
我正在使用C#和WPF,我基本上想要一些切换按钮,并且只能同时选择其中一个.
我发现了另一个问题,但是那里显示的解决方案不起作用,我不知道为什么.
如果我尝试做在上面的问题中提到的ItemTemplate的ListBox不适用.我只是没有将切换按钮放入列表框,而是显示为"正常列表框".
我的切换按钮样式如下所示,包含在我的一个资源文件中:
<Style x:Key="ToggleButtonListBox" TargetType="{x:Type ListBox}">
<Setter Property="ListBox.ItemTemplate">
<Setter.Value>
<DataTemplate>
<ToggleButton Content="{Binding}"
IsChecked="{Binding IsSelected, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBoxItem}}}" />
</DataTemplate>
</Setter.Value>
</Setter>
<Setter Property="ListBox.ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
<Setter Property="BorderThickness" Value="0" />
</Style>
Run Code Online (Sandbox Code Playgroud)
我想直接在XAML代码中添加项目,所以我的代码看起来像
<ListBox Style="{StaticResource ToggleButtonListBox}">
<ListBoxItem>test1</ListBoxItem>
<ListBoxItem>test2</ListBoxItem>
</ListBox>
Run Code Online (Sandbox Code Playgroud)
如何创建这样一组按钮?
我想做什么
我正在尝试在我的布局中使用Android 4.0样式的togglebutton.为此,我选择了Theme = Theme.Holo.Light.当我从那里拿到togglebutton时,如果按钮被启用,则该绿色线的正方形.
但我想使用togglebutton就像他们在那里配置顶部(看看打印屏幕).
题
我怎么能用这个togglebutton?一些Codesnippets或快速教程会很棒!
最好的祝福
苹果浏览器
图片

我想创建一个这样的Android默认值ToggleButton:
但我想在没有TEXT的情况下创建它
我尝试使用此代码:
ToggleButton tb = new ToggleButton(map);
tb.setText(null);
tb.setTextOn(null);
tb.setTextOff(null);
Run Code Online (Sandbox Code Playgroud)
但它在水平绿色条的顶部留下一个空的空间.
我不想要那个空的空间,我只想要水平的绿色条.
怎么实现呢?
谢谢
我尝试使用XML文件更改切换按钮的背景颜色为白色,但切换按钮完全损坏.看起来所有按钮都覆盖着白色.
将切换按钮的颜色更改为白色时,切换按钮上没有ON或OFF的指示.是否有另一种改变背景的方法,不会损坏切换按钮的指示?
<ToggleButton android:id="@+id/togglebutton"
android:layout_width="100px"
android:layout_height="46px"
android:background="#ffffff"
android:layout_above ="@+id/save"
android:textOn="DAY"
android:textOff="NIGHT" />
Run Code Online (Sandbox Code Playgroud)
这就是我的XML代码查找切换按钮的方式.
我想模仿一组ToggleButtons的样式,如下图所示.任何时候只能"检查"其中一个按钮.

我的问题与样式有关:
我正在使用的当前控件是这样完成的:
<StackPanel Orientation="Horizontal" >
<RadioButton Style="{StaticResource {x:Type ToggleButton}}" Content="All" Padding="12,8,12,8" GroupName="View" />
<RadioButton Style="{StaticResource {x:Type ToggleButton}}" Content="Geolocated" Padding="12,8,12,8" GroupName="View" />
<RadioButton Style="{StaticResource {x:Type ToggleButton}}" Content="Non Geolocated" Padding="12,8,12,8" GroupName="View" />
</StackPanel>
Run Code Online (Sandbox Code Playgroud)
在StackPanel资源中,我试图为ToggleButton设置Style,但我很遗憾如何在上图中获得结果.
我正在尝试实现的是下面图像的基本和精确的复制品(我已经平方的偏好).按下首选项左侧的任何内容都应该打开一个对话框.按下togglebutton将禁用/启用我在此首选项中设置的任何内容.
我一直在努力工作几个小时,而且我空手而归.如何在PreferenceActivity中实现此功能?

编辑:似乎人们误解了我的问题.我弄清楚如何使用PreferenceActivity解决我的问题非常重要.不是活动.我不在乎我是需要用XML还是以编程方式来做.请不要向我提供我不能在类似内容中使用的答案.
编辑2:增加了赏金 - 我真的需要一个答案
我在我的C#WPF应用程序中有一个ToggleButton,我想将一个Command绑定到Checked事件,将一个Command绑定到Unchecked事件.
我目前的情况如下:
<ToggleButton Name="btnOpenPort" Style="{StaticResource myOnOffBtnStyle}" Content="Open Port"
Checked="btnOpenPort_Checked" Unchecked="btnOpenPort_Unchecked"
IsChecked="{Binding Path=PortViewModel.PortIsOpen, Mode=OneWay}"
Canvas.Left="75" Canvas.Top="80" Height="25" Width="100"/>
Run Code Online (Sandbox Code Playgroud)
但这不是我的目标.因为在这种情况下,我必须在Checked和Unchecked事件的代码后面设置属性.相反,我想在Checked或Unchecked事件被触发后在我的ViewModel中调用一个Command(ICommand),这样我的切换按钮后面不需要任何代码.
有没有办法直接为XAML中的这两个事件绑定命令?类似于WPF中"标准"按钮控件的命令属性?
编辑 这是关于@ har07提示的工作原理:
1:如果您还没有参考,请添加参考:
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:ei="clr-namespace:Microsoft.Expression.Interactivity.Core;assembly=Microsoft.Expression.Interactions"
Run Code Online (Sandbox Code Playgroud)
2:已检查和未检查事件的已实现Interaction.Triggers:
<ToggleButton
Name="btnOpenPort" Style="{StaticResource myOnOffBtnStyle}" Content="Open Port"
IsChecked="{Binding Path=PortViewModel.PortIsOpen, Mode=OneWay}"
Canvas.Left="75" Canvas.Top="80" Height="25" Width="100">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Checked">
<i:InvokeCommandAction Command="{Binding Path=PortViewModel.OpenPort}"/>
</i:EventTrigger>
<i:EventTrigger EventName="Unchecked">
<i:InvokeCommandAction Command="{Binding Path=PortViewModel.ClosePort}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</ToggleButton>
Run Code Online (Sandbox Code Playgroud)
有了这个解决方案,我不必在我的ViewModel或后面的代码中更改一行代码.我可以调用我的ICommand,就像我在MVVM模式下使用标准按钮一样.
togglebutton ×10
android ×6
wpf ×4
radio-button ×2
xaml ×2
android-4.0-ice-cream-sandwich ×1
binding ×1
button ×1
command ×1
grid ×1
gridsplitter ×1
layout ×1
listbox ×1
preferences ×1
styles ×1