- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有这个 Border
样式:
<Border.Style>
<Style x:Uid="Style_36" TargetType="Border">
<Setter x:Uid="Setter_94" Property="BorderBrush" Value="Transparent"/>
<Style.Triggers>
<DataTrigger x:Uid="DataTrigger_36" Binding="{Binding SelectedItem, ElementName=comboActiveStudentAssignmentType}"
Value="{x:Static StudentInfoEnums:StudentAssignmentType.Student1Main}">
<Setter x:Uid="Setter_95" Property="BorderBrush" Value="Red"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Border.Style>
我知道如何将样式放入 Window.Resources
,然后将其应用于任何控件。但我需要调整每个实例。文中:
<Border.Style>
<Style x:Uid="Style_36" TargetType="Border">
<Setter x:Uid="Setter_94" Property="BorderBrush" Value="Transparent"/>
<Style.Triggers>
<DataTrigger x:Uid="DataTrigger_36" Binding="{Binding SelectedItem, ElementName=comboActiveStudentAssignmentType}"
Value="{x:Static StudentInfoEnums:StudentAssignmentType.Student1Main}">
<Setter x:Uid="Setter_95" Property="BorderBrush" Value="Red"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Border.Style>
这个位:
Value="{x:Static StudentInfoEnums:StudentAssignmentType.Student1Main}">
需要为窗口上的每个 Border
进行更改。那么,我如何设置样式来简化我的代码,同时允许更改此属性?
可能吗?
由于每个边框只应在组合为特定值时显示,建议将所有数据触发器放入样式模板中,我开始尝试:
<Style x:Uid="Style_38" x:Key="StudentAssignmentFocusedBorder" TargetType="Border">
<Setter x:Uid="Setter_94" Property="BorderBrush" Value="Transparent"/>
<Style.Triggers>
<MultiDataTrigger x:Uid="MultiDataTrigger_5">
<MultiDataTrigger.Conditions>
<Condition x:Uid="Condition_11" Binding="{Binding SelectedtItem, ElementName=comboActiveStudentAssignmentType}" Value="{x:Static StudentInfoEnums:StudentAssignmentType.Student1Main}"/>
<Condition x:Uid="Condition_12" Binding="{Binding Name, Mode=OneWay, RelativeSource={RelativeSource Self}}" Value="borderMainHallStudent1"/>
</MultiDataTrigger.Conditions>
<Setter x:Uid="Setter_95" Property="BorderBrush" Value="Red"/>
</MultiDataTrigger>
</Style.Triggers>
</Style>
但这行不通。
最佳答案
这不很漂亮,但可以增加您的可能性,因为您可以绑定(bind)您的StudentInfoEnums:StudentAssignmentType.Student1Main
-Enum。
一些随机演示 - XAML 测试:
<Window x:Class="SelectButtonSample.MainWindow"
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"
xmlns:local="clr-namespace:SelectButtonSample"
mc:Ignorable="d"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
Title="MainWindow" >
<Grid Height="200">
<StackPanel>
<Button Content="Click me" Width="80" Height="20" >
<i:Interaction.Behaviors>
<local:MyBorderBehavior MyEnumPropery="Two"/>
</i:Interaction.Behaviors>
</Button>
<CheckBox Content="Click me" x:Name="chk">
<i:Interaction.Behaviors>
<local:MyBorderBehavior MyEnumPropery="Three"/>
</i:Interaction.Behaviors>
</CheckBox>
<ListView>
<i:Interaction.Behaviors>
<local:MyBorderBehavior MyEnumPropery="One"></local:MyBorderBehavior>
</i:Interaction.Behaviors>
<ListViewItem Content="Item1">
<i:Interaction.Behaviors>
<local:MyBorderBehavior MyEnumPropery="Four"></local:MyBorderBehavior>
</i:Interaction.Behaviors>
</ListViewItem>
<ListViewItem>Item 2</ListViewItem>
<ListViewItem>Item 3</ListViewItem>
<ListViewItem>Item 4</ListViewItem>
</ListView>
</StackPanel>
</Grid>
</Window>
我的演示枚举:
public enum MyEnum
{
One,
Two,
Three,
Four
}
魔法:
public class MyBorderBehavior : Behavior<Control>
{
public MyEnum MyEnumPropery {
get { return (MyEnum) GetValue(MyEnumProperyProperty); }
set { SetValue(MyEnumProperyProperty, value); }
}
public static readonly DependencyProperty MyEnumProperyProperty = DependencyProperty.Register("MyEnumPropery", typeof(MyEnum), typeof(MyBorderBehavior), new PropertyMetadata(PropertyChangedCallback));
private static void PropertyChangedCallback(DependencyObject dO, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
{
var self = dO as MyBorderBehavior;
if (self != null && self._controlToColorBorder != null)
self.SetColor();
}
private Control _controlToColorBorder;
private void SetColor()
{
switch (this.MyEnumPropery)
{
case MyEnum.One:
this._controlToColorBorder.BorderBrush = Brushes.Yellow;
break;
case MyEnum.Two:
this._controlToColorBorder.BorderBrush = Brushes.Red;
break;
case MyEnum.Three:
this._controlToColorBorder.BorderBrush = Brushes.Green;
break;
case MyEnum.Four:
this._controlToColorBorder.BorderBrush = Brushes.DeepPink;
break;
}
}
protected override void OnAttached()
{
this._controlToColorBorder = this.AssociatedObject;
this._controlToColorBorder.Loaded += ControlToColorBorderLoaded;
base.OnAttached();
}
private void ControlToColorBorderLoaded(object sender, RoutedEventArgs e)
{
this.SetColor();
}
}
注意事项:
System.Windows.Interactivity
-程序集Behavior
可以应用于Control
类型的一切(因为控件有 BorderBrush
-Property)DependencyProperty
来使事物可绑定(bind)。MyEnum
和调整颜色。此外,您可能必须实现另一个DependencyProperty
将您的第二个条件带到行为中。希望这能为您提供线索,让您了解如何继续编写代码。
关于c# - 设置边框样式模板,但允许灵活使用值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38480443/
我有以下几行代码: using XXX.PAD.PaidServices; using YYY= XXX.PAD.PaidServices.Judet; //// uncomment below fo
我正在寻找一种方法,让 LAN 中的客户端无需任何配置即可找到我的服务器应用程序的所有实例。我不想自己破解某些东西,而是想使用现有的解决方案。就个人而言,我需要用 Python 完成它,但我很乐意听到
我的“问题”或“挑战”有很多问题。但它们都不符合我的需求。好的,我开始了: 我想要一个保存可变属性的数据库。现在我将它们作为列名“硬编码”到数据库中(参见图片)。请参阅“颜色”和“尺寸”。但是如果我想
我正在为我的一个 friend 创建一个网站。我们得到了这些布局,我已经放了一个灵活的背景,可以缩放到当前的浏览器大小。但是放置在背景上的图标需要在缩放窗口时保持相对位置。意味着如果我调整窗口大小,让
案例 通常,您会使用 cellForRowAtIndexPath 委托(delegate)方法来设置单元格。单元格的信息集对于单元格的绘制方式和大小非常重要。 不幸的是,heightForRowAtI
我试图让下面的 div 变得灵活 div { min-width: 500px; max-width: 1000px; width:100%; height: 400px; margin-left:1
我在单元测试方面遇到问题。当我运行测试时,它以 "No tests found" 结束。我正在使用 AppCode 和 Quick/Nimble 框架进行单元测试,但它在 XCode 中也不起作用。
问之前,请理解我的英语不好。 我在 servlet 编程中使用 Class.forName(...) 类。当我访问 servlet 时,我从数据库中获得一行详细的 Controller 信息,指示要使
我创建了一个cron job在 GAE 灵活环境中,每 15 分钟自动运行一次。 但是在创建每个实例时,是否会为每个实例复制相同的 cron 作业?我对此不太确定。 最佳答案 不,不会为每个实例复制
div A 灵活且固定(位于窗口顶部),具有高 z-index,因此下方的元素可以在滚动时从下方通过。 div B 位于 div A 下方,我希望它“粘”在 div A 的底部,因为在调整窗口大小时高
我是 Quick/Nimble 的新手,所以我尝试了一个简单的单元测试: import Quick import Nimble class DarkSkyTests: QuickSpec {
我创建了一个演示。关于表格单元格的灵 active ,我需要一些帮助。 我有一些表格单元格,它们的宽度应该是固定的。 但单元格由标签组成,标签可以是长文本,也可以是短文本。 基于此标签,表格单元格应该
我非常熟悉在代码中需要“水平带”的网站 - 即使他们的内容固定在 960 像素以内,他们的背景也会向左和向右“延伸”。 我知道如何做这些,如果它们只有一种颜色,或者我可以用作背景的一张图片。 最近一位
我在自己编写的网站(无框架或 CMS)上使用 Cloudflare Flexible SSL。一切正常,现在我想在整个网站上使用 HTTPS。我在 Apache Web 服务器上使用 PHP。 我想知
我有这个 Java 接口(interface): public interface Box { public void open(); public void close(); } 这个接
所以我有一个“主要”功能系统,现在可以作为 CMS 使用:用户进入编辑器并从四个模板中选择一个。在模板中,他们单击可以添加图像、文本或两者的部分。 我有一个预览屏幕,可以向他们展示他们正在制作的东西,
下面的 HTML/CSS/Javascript (jQuery) 代码显示了 #makes 选择框。选择一个选项会显示带有相关选项的 #models 选择框。 #makes 选择框偏离中心,#mode
我正在使用固定高度的图像来填充具有渐变颜色的 div,方法如下:背景:透明 url(green_bg.gif) repeat-x scroll 0 0; 但是它只填充一个等于图像高度的高度。根据其中的
我的系统的 GUI 在 1366 X 768 分辨率下运行良好。当它以不同的分辨率显示时,我需要并排滚动,而它不应该这样。此外,当我尝试在 chrome 中按 ctr+- 时,div 和部分变得困惑。
我正在尝试在 google app engine 灵活环境中使用 python 编写日志。 我想使用默认的 python 日志记录库并使用处理程序进行日志记录。这是我的代码: import loggi
我是一名优秀的程序员,十分优秀!