小编ds3*_*345的帖子

在WPF中在运行时更改样式

我试图允许用户自定义WPF应用程序中的元素.我想要实现的是,如果我有一个列表框,指定所有表单元素(TextBox,标签等),用户可以选择一个表单元素,并设置样式属性说标签,前景应该是橙色的,其中至于TextBox前景应为黑色,依此类推.根据我打算应用的样式,所有TextBox都应该看起来很相似.

我无法找到实现这一目标的方法.我已经尝试了一个示例,其中可以在运行时上载多个预定义的样式.所以现在,我想找到一种在运行时更改不同元素的属性的方法.

UPDATE:

我试图从后面的代码创建一个新的样式.

XAML

<Label Content="SAMPLE" Style="{DynamicResource Style1}" x:Name="label1" />
<Button Content="Button" Click="Button_Click" />
Run Code Online (Sandbox Code Playgroud)

并在代码后面,即点击按钮我试过这个:

Style style = new Style { TargetType = typeof(Label) };
style.Setters.Add(new Setter(Control.ForegroundProperty, Brushes.Black));
Application.Current.Resources["Style1"] = style;
Run Code Online (Sandbox Code Playgroud)

但它没有得到更新.

谢谢.

c# wpf styles

17
推荐指数
2
解决办法
4万
查看次数

将相同的样式应用于多个元素

我是新来使用WPF和我尝试应用Style(例如,背景为TextBox,Button并且MenuItem应该是橙色).为此,我做了类似的事情:

<Style TargetType="TextBox" x:Key="sampleTextBox">
    <Setter Property="Margin" Value="2"/>
    <Setter Property="FontFamily" Value="Verdana"/>
    <Setter Property="FontSize" Value="11px"/>
    <Setter Property="FontWeight" Value="Bold"/>
    <Setter Property="Background">
        <Setter.Value>
            <LinearGradientBrush StartPoint="0,0" EndPoint="0,1" >
                <GradientStop Color="#FFFFD190" Offset="0.2"/>
                <GradientStop Color="Orange" Offset="0.85"/>
                <GradientStop Color="#FFFFD190" Offset="1"/>
            </LinearGradientBrush>
        </Setter.Value>
    </Setter>
</Style>
Run Code Online (Sandbox Code Playgroud)

并重复了targettype Button和目标菜单的相同代码.这工作绝对正常.但我想通过可能具有多个targettype值来最小化重复代码的数量.

如果可能,请告诉我.

谢谢.

wpf xaml styles

5
推荐指数
1
解决办法
1930
查看次数

获取数据包的源地址和端口号 - Scapy脚本

我正在嗅探网络并尝试在每个tcp数据包上获取IP地址和端口号.

我使用scapy和python并且可以成功地嗅探数据包,并且在回调函数中甚至可以打印数据包摘要.但我想做更多,比如只获取源的IP地址及其端口号.我怎么能完成它?以下是我的代码:

#!/usr/bin/evn python
from scapy.all.import.*
def print_summary(pkt):
    packet = pkt.summary()
    print packet
sniff(filter="tcp",prn=packet_summary)
Run Code Online (Sandbox Code Playgroud)

请建议一种只打印每个数据包的源IP地址的方法.

谢谢.

networking tcp scapy python-2.7

5
推荐指数
1
解决办法
2万
查看次数

在javascript中设置单选按钮值

我试图通过javascript设置单选按钮的值.但我无法这样做.我试图做的是有4个单选按钮,其中一个已被选中.如果我选择其他单选按钮并单击"刷新",则应选择默认单选按钮.

http://jsfiddle.net/ds345/Un8XK/1/

HTML:

<fieldset data-role="controlgroup" data-type="vertical">
    <input type="radio" name="radio" id="x" data-theme="a" />
    <label for="x" style="color: White">X</label>
    <input type="radio" name="radio" id="y" onclick="axisonoff(this)" data-theme="a" />
    <label for="y" style="color: White">Y</label>
    <input type="radio" name="radio" id="z" data-theme="a" />
    <label for="z" >Z</label>
    <input type="radio" name="radio" id="none" data-theme="a" />
    <label for="none" style="color: White">None</label>
</fieldset>


<button id = "Refresh" value="Refresh">Refresh</button>
Run Code Online (Sandbox Code Playgroud)

JS:

$(document).ready(function () {
    $("#none").attr("checked", true).checkboxradio("refresh"); // if this line is not present initially then it works for the 1st refresh. 

});

$("#Refresh").click(function(){
        $("#x").attr("checked", false).checkboxradio("refresh");
        $("#y").attr("checked", false).checkboxradio("refresh");
        $("#z").attr("checked", …
Run Code Online (Sandbox Code Playgroud)

html javascript jquery jquery-mobile

1
推荐指数
1
解决办法
1万
查看次数

标签 统计

styles ×2

wpf ×2

c# ×1

html ×1

javascript ×1

jquery ×1

jquery-mobile ×1

networking ×1

python-2.7 ×1

scapy ×1

tcp ×1

xaml ×1