如果我有两个200行长的控制模板,只有几个字(几种颜色)不同,我怎样才能使xaml可重用?也就是说,不必复制粘贴模板并在200行中更改3个单词.
这是一个简化的例子.两种风格的唯一区别是边框颜色.那么我能以某种方式定义ButtonStyle,使用参数化颜色,并从中继承BlackButtonStyle和GrayButtonStyle,并在BlackButtonStyle和GrayButtonStyle中仅指定该颜色吗?
alt text http://img444.imageshack.us/img444/9545/buttonstyles.png
<Window x:Class="WpfApplication33.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Window.Resources>
<Style x:Key="BlackButtonStyle" TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border BorderBrush="Black" BorderThickness="3">
<ContentControl Content="{TemplateBinding Content}"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="GrayButtonStyle" TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border BorderBrush="Gray" BorderThickness="3">
<ContentControl Content="{TemplateBinding Content}"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<StackPanel>
<Button Content="Black Button"
Style="{StaticResource BlackButtonStyle}"/>
<Button Content="Gray Button"
Style="{StaticResource GrayButtonStyle}"/>
</StackPanel>
</Window>
Run Code Online (Sandbox Code Playgroud)
这是基于2个答案的代码.只需要在控件上设置样式,但不幸的是它仍然会混淆控件的标记:
<Window x:Class="WpfApplication33.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Window.Resources>
<Style x:Key="ButtonStyle" …Run Code Online (Sandbox Code Playgroud) 所以我正在尝试执行一个shell脚本,它从Java文件中产生大量输出(以100s为单位).这会挂起进程并永远不会完成.
但是,在shell脚本中,如果我将脚本的输出重定向到某个日志文件或/ dev/null Java文件执行并在jiffy中完成.
是因为Java程序永远不会完成的数据量?如果是的话,有没有这样的文件?或者数据量是否有限制(记录在案)?
以下是模拟此场景的方法.
Java文件看起来像:
import java.io.InputStream;
public class LotOfOutput {
public static void main(String[] args) {
String cmd = "sh a-script-which-outputs-huuggee-data.sh";
try {
ProcessBuilder pb = new ProcessBuilder("bash", "-c", cmd);
pb.redirectErrorStream(true);
Process shell = pb.start();
InputStream shellIn = shell.getInputStream();
int shellExitStatus = shell.waitFor();
System.out.println(shellExitStatus);
shellIn.close();
} catch (Exception ignoreMe) {
}
}
}
Run Code Online (Sandbox Code Playgroud)
脚本'a-script-which-outputs-huuggee-data.sh'可能如下所示:
#!/bin/sh
# Toggle the line below
exec 3>&1 > /dev/null 2>&1
count=1
while [ $count -le 1000 ]
do
cat some-big-file
((count++))
done …Run Code Online (Sandbox Code Playgroud) 在我阅读帖子时,我想到了这个问题为什么C#不支持多重继承? 来自MSDN博客.
首先看下面的代码:
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class A
{
int num;
public A()
{
num = 0;
}
public A(int x)
{
num = x;
}
public override int GetHashCode()
{
return num + base.GetHashCode();
}
}
class B : A
{
int num;
public B()
{
num = 0;
}
public B(int x)
{
num = x;
}
public override int GetHashCode()
{
return num + base.GetHashCode();
}
}
class …Run Code Online (Sandbox Code Playgroud) 我的一些代码需要JCE无限强度策略文件.我想将这个依赖项添加到Maven Pom文件中,这样我团队中的其他开发人员就不必单独将它们应用到他们的系统中.
我意识到最终部署的系统需要手动安装JCE文件.这只是一个开发解决方案.
我以为我们会将策略文件添加到我们的存储库,maven将能够处理安装,但我很惊讶我找不到其他人这样做(以及关于它的博客).
当我在Matlab中创建一个图形时,在将图形导出到eps(或pdf)时,有一个图例和一个接触y轴的矩形(奇怪,我知道)我注意到矩形获得了最后一行的线条样式绘制的线条(而不是绘制的矩形)
对于接触轴的矩形后绘制的矩形也会发生此行为...
如果在创建图例之前绘制矩形,则不会发生这种情况....
不用说,创建一个最小的例子我花了半天时间:
clf
L=plot(X,sin(X),'--');
legend(L,'sin(x)')
rectangle('position',[0.001,.1,.7,.7])
rectangle('position',[0,.5,.6,.7])
rectangle('position',[0.001,.3,.5,.7])
%legend(L,'sin(x)')
Run Code Online (Sandbox Code Playgroud)
在屏幕上,3矩形有实线,正如它们应该的那样.但是一旦它们被导出,结果就会有最后两行用虚线(比如sin(x)).如果传奇命令稍后完成(如注释掉的那一行),一切都按原样运行....
这是一个功能还是一个bug?
最近,当我看到google结果页面时,查询和其他参数传递了#(hash)而不是通常的"?"
此外,在Facebook我看到了同样的事情.这非常有趣,经过谷歌的简单搜索,我发现结果与perl和Ruby相关,但没有PHP的结果.
是否可以在PHP中使用#而不是"?"传递参数 或者这只能用perl/Ruby实现.这将非常有用,搜索引擎不会解析URL中的参数.
任何想法都会对我有所帮助.
我最近遇到了一些代码,它使用自定义错误处理程序将任何PHP错误转换为通用应用程序异常.还定义了一个自定义异常处理程序,如果异常位于特定的错误代码范围内,它将记录该异常.例:
class AppException extends Exception
{
}
function error_handler($errno, $errstr, $errfile, $errline)
{
throw new AppException($errstr, $errno);
}
function exception_handler($exception)
{
$min = ...;
$max = ...;
if ($exception->getCode() >= $min && $exception->getCode() <= $max)
{
// log exception
}
}
set_error_handler('error_handler');
set_exception_handler('exception_handler');
$a[1]; // throws exception
Run Code Online (Sandbox Code Playgroud)
问题是我看到了以下内容:
try
{
do_something();
}
catch (AppException $exception)
{
}
Run Code Online (Sandbox Code Playgroud)
这意味着实际编程错误与"异常"行为之间没有区别.在进一步挖掘之后,我发现了围绕PHP错误代表"异常"行为的想法设计的部分代码,例如:
...
function my_function($param1, $param2)
{
// do something great
}
try
{
my_function('only_one_param');
}
catch (AppException $exception)
{
}
Run Code Online (Sandbox Code Playgroud)
这最终会混淆错误和应用程序界面的设计.
您对这种处理错误有何看法?是否值得将PHP的原生错误转化为异常?在上述代码库是围绕这个想法设计的情况下你做了什么?
).今天我用TcpListener遇到了一些问题.事情很奇怪.最初,我使用了新的TcpListener(port)构造函数,但是它已被标记为已过时.所以我放弃了它并使用了它:
IPAddress ipAddress = Dns.GetHostEntry(Dns.GetHostName()).AddressList[0];
IPEndPoint ipLocalEndPoint = new IPEndPoint(ipAddress, ServerPort);
TcpListener tcpServer = new TcpListener(ipLocalEndPoint);
_TCPClient = tcpServer.AcceptTcpClient();
GotClient();
Run Code Online (Sandbox Code Playgroud)
当然,我在一个线程中这样做,因此它不会锁定应用程序.现在,那里发生的是,即使ipAddress正确,服务器也不会接受任何传入连接.
但是,更改为新的IPEndPoint(IPAddress.Any,ServerPort)似乎可以解决问题!这有两个方面很愚蠢:
2小时前,IPAddress.Any返回192.168.1.102这是我正确的本地IP.这与 ipAddress中的IP 相同!但是使用ipAddress它不起作用,而使用IPAddress.Any它工作(即,它成功接受来自我的客户端的连接).
现在:IPAddress.Any返回0.0.0.0( !?而ip地址变量继续被赋予我的正确IP(192.168.1.102)).结果?如果使用ipAddres,我的客户端仍然无法连接,但在使用IPAddress.Any时连接,即使它是0.0.0.0.
我对这完全感到困惑......有什么想法吗?
我目前在Form_HandleCreated中有这个,但是当我在Form的构造函数中使用它时它表现得很奇怪.
后期编辑:我认为我错了IPAddress.Any返回192.168.1.102.我可能打印出别的东西,因为很多人都指出0.0.0.0是什么.Any应该返回.对不起:: - D.
我已经在Stackoverflow和谷歌搜索过,但还没找到我想要的东西.
到目前为止,我得到了音频原始数据(WAV文件),我想要将其可视化.
private void Form1_Load(object sender, EventArgs e)
{
FileStream fs = new FileStream("D:\\tada.wav", FileMode.Open);
BinaryReader reader = new BinaryReader(fs);
char[] data = new char[4];
long fsize;
long wfxSize;
long dataSize;
WaveFormatEx wfx;
//RIFF
reader.Read(data, 0, 4);
fsize = reader.ReadInt32();
//WAVE
reader.Read(data, 0, 4);
//FMT
reader.Read(data, 0, 4);
wfxSize = reader.ReadInt32();
byte[] wfxBuffer = new byte[wfxSize];
reader.Read(wfxBuffer, 0, (int)wfxSize);
wfx = new WaveFormatEx(wfxBuffer);
//DATA
reader.Read(data, 0, 4);
dataSize = reader.ReadInt32();
byte[] dataBuff = new byte[dataSize];
reader.Read(dataBuff, 0, (int)dataSize);
reader.Close();
//Visualize …Run Code Online (Sandbox Code Playgroud)