假设我需要在WPF控件上设置不透明蒙板,在高精度位置突出显示它的一部分(假设位于(50; 50)位置的50x50平方).为此,我创建了一个包含2个GeometryDrawing对象的DrawingGroup:1个半透明矩形用于控件的整个实际大小,1个不透明矩形用于突出显示的区域.然后我从这个DrawingGroup创建一个DrawingBrush,将它的Stretch属性设置为None,并将此画笔设置为需要屏蔽的控件的OpacityMask.
所有这一切都很好,而没有任何东西"坚持"超出所述控制的范围.但是如果控制在界限之外绘制某些东西,则外部点将成为应用不透明蒙版的起点(如果画笔与该侧对齐)并且整个蒙版移动该距离会导致意外行为.
我似乎无法找到一种方法来强制从控件的边界应用蒙版或至少获得控件的实际边界(包括粘贴部分),这样我就可以相应地调整我的蒙版.
任何想法高度赞赏!
更新:这是一个简单的测试用例XAML和截图,展示了这个问题:
我们在最后一个中有2个嵌套的Borders和Canvas,带有上面提到的方块:
<Border Padding="20" Background="DarkGray" Width="240" Height="240">
<Border Background="LightBlue">
<Canvas>
<Rectangle Canvas.Left="50" Canvas.Top="50" Width="50" Height="50"
Stroke="Red" StrokeThickness="2"
Fill="White"
/>
</Canvas>
</Border>
</Border>
Run Code Online (Sandbox Code Playgroud)
以下是它的外观:
没有面具http://devblog.ailon.org/devblog/_stuff/maskissue/square-no-mask.gif
现在我们将OpacityMask添加到第二个边框,这样除了我们的方块之外,它的每个部分都是半透明的:
<Border.OpacityMask>
<DrawingBrush Stretch="None" AlignmentX="Left" AlignmentY="Top">
<DrawingBrush.Drawing>
<DrawingGroup>
<GeometryDrawing Brush="#30000000">
<GeometryDrawing.Geometry>
<RectangleGeometry Rect="0,0,200,200" />
</GeometryDrawing.Geometry>
</GeometryDrawing>
<GeometryDrawing Brush="Black">
<GeometryDrawing.Geometry>
<RectangleGeometry Rect="50,50,50,50" />
</GeometryDrawing.Geometry>
</GeometryDrawing>
</DrawingGroup>
</DrawingBrush.Drawing>
</DrawingBrush>
</Border.OpacityMask>
Run Code Online (Sandbox Code Playgroud)
一切看起来都像预期的那样
蒙面的http://devblog.ailon.org/devblog/_stuff/maskissue/square-mask.gif
现在我们在画布上添加一条线,在我们的边框左侧粘贴10个像素:
<Line X1="-10" Y1="150" X2="120" Y2="150"
Stroke="Red" StrokeThickness="2"
/>
Run Code Online (Sandbox Code Playgroud)
并且掩码向左移动10个像素:
转移掩码http://devblog.ailon.org/devblog/_stuff/maskissue/square-line-mask.gif
Update2:作为一种解决方法,我在边界外添加一个可笑的大透明矩形并相应地调整我的面具,但这是一个非常讨厌的解决方法.
Update3:注意:带有矩形和直线的画布就像某个对象的例子一样,它有一些超出界限的对象.在此示例的上下文中,它应被视为某种黑盒子.您无法更改其属性来解决一般问题.这与移动线条相同,因此不会突出.
来自C风格语法的悠久历史,现在正在尝试学习Ruby(在Rails上),我一直在用它的成语等问题分享我的问题,但今天我遇到了一个我没想到会出现问题的问题.我无法看到任何必须在我面前的东西.
我有一个二进制类,其中包含一个私有方法,用于从路径值派生URI值(uri和路径是类的属性).我打电话self.get_uri_from_path()从内部Binary.upload(),但我得到:
Attempt to call private method
Run Code Online (Sandbox Code Playgroud)
该模型的片段如下所示:
class Binary < ActiveRecord::Base
has_one :image
def upload( uploaded_file, save = false )
save_as = File.join( self.get_bin_root(), '_tmp', uploaded_file.original_path )
# write the file to a temporary directory
# set a few object properties
self.path = save_as.sub( Rails.root.to_s + '/', '' )
self.uri = self.get_uri_from_path()
end
private
def get_uri_from_path
return self.path.sub( 'public', '' )
end
end
Run Code Online (Sandbox Code Playgroud)
我打电话不正确吗?我错过了一些更基本的东西吗?目前唯一Binary.get_uri_from_path()被调用的地方是 - Binary.upload().我希望能够在同一个类中调用私有方法,除非Ruby做了与我使用的其他语言明显不同的东西.
谢谢.
我正在使用dotnetopenauth 3.2来实现Openid,并且无法弄清楚如何让Google在声明响应中传递电子邮件地址.我知道Google不支持简单注册,但我无法确定他们支持的内容.
对这个问题的警告是我刚刚开始学习OpenID,我知道我对规范没有扎实的把握,我认为这导致了我的困惑.
任何帮助,将不胜感激!
我最近使用cvs2svn将我的cvs存储库转换为svn,我最近注意到每个目录都有一个名为.svn的隐藏文件夹.我当前的构建脚本从我的版本化资源目录中复制了很多目录,最终复制了.svn文件.无论如何在我结账时让svn不包含这些文件,或者我是否需要编写脚本来删除所有这些.svn文件.有许多文件具有这些隐藏的.svn目录,所以这将是一个痛苦,除非我可以编写一个递归脚本来执行此操作,但我不会,如果我可以为我的Windows安装程序执行此操作.有没有一种简单的方法可以阻止svn将这个隐藏目录放在我的项目中的任何地方?
有没有办法知道我目前所处方法的名称?
以便:
procedure TMyObject.SomeMethod();
begin
Writeln('my name is: ' + <hocus pocus>);
end;
Run Code Online (Sandbox Code Playgroud)
会产生这个输出:
my name is: SomeMethod
我正在研究类路径的动态修改.我找到了一个可以正常工作的解决方案,但它使用显式调用addURL()来实现.(大概是在启动时)
但是,如果默认的类加载器似乎无法找到它,我想在运行时拦截类加载过程以找到类.我试图将ClassLoader子类化,因此它只是委托findClass()和loadClass()默认,并打印出一个调试行告诉我这些方法已被调用,但是当我的类通过隐式类加载使用依赖类时,它们似乎永远不会被调用,例如
// regular object instantiation with 'new'
BrowserLauncher launcher;
launcher = new BrowserLauncher();
// static methods
Foobar.doSomethingOrOther();
// Class.forName()
Class cl = Class.forName("foo.bar.baz");
// reflection on a Class object obtained statically
Class<Foobar> cl = Foobar.class;
// do something with cl, like call static methods or newInstance()
Run Code Online (Sandbox Code Playgroud)
在这些情况下,类加载如何工作?(相对于显式调用Classloader.loadClass()的简单情况)
这是我在下面的自定义类加载器的尝试.如果我使用带有参数列表的DynClassLoader0.main(){"some.package.SomeClass", "foo", "bar", "baz"},并且some.package.SomeClass引用外部.jar文件中的其他类,使用上面列出的方法之一,为什么我的DynClassLoader0的findClass()和loadClass不是( )被叫?loadClass被调用的唯一时间是在下面的main()函数中对loadClass的显式调用.
package com.example.test.classloader;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class DynClassLoader0 extends ClassLoader { …Run Code Online (Sandbox Code Playgroud) 我有一个数字,需要添加一个小数来格式化.
这个数字保证在1000到999999之间(我已经用其他方式涵盖了其他可能性,这是我无法理解的).我需要在最后3位数之前加一个小数,例如:
1000 -> 1.000
23513 -> 23.513
999999 -> 999.999
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
我有一个简单的C++与Boost像这样:
#include <boost/algorithm/string.hpp>
int main()
{
std::string latlonStr = "hello,ergr()()rg(rg)";
boost::find_format_all(latlonStr,boost::token_finder(boost::is_any_of("(,)")),boost::const_formatter(" "));
Run Code Online (Sandbox Code Playgroud)
这很好用; 它取代了每次出现的(),用""
但是,我在编译时收到此警告:
我正在使用MSVC 2008,Boost 1.37.0.
1>Compiling...
1>mainTest.cpp
1>c:\work\minescout-feat-000\extlib\boost\algorithm\string\detail\classification.hpp(102) : warning C4996: 'std::copy': Function call with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\xutility(2576) : see declaration of 'std::copy'
1> c:\work\minescout-feat-000\extlib\boost\algorithm\string\classification.hpp(206) : see …Run Code Online (Sandbox Code Playgroud) 我正在尝试为特定的工程应用程序设计一个类库,我正在努力确保我的类和命名空间命名约定有意义.
我有以下情况:
namespace Vehicle{
class Wheel{...} //base class for Wheel objects
class Engine{...} //base class for Engine objects
...
namespace Truck{
class Wheel: Vehicle.Wheel{...} //Truck specific Wheel object
class Engine: Vehicle.Engine{...} //Truck specific Engine object
...
}
namespace Car{
class Wheel: Vehicle.Wheel{...} //Car specific Wheel object
class Engine: Vehicle.Engine{...} //Car specific Engine object
...
}
...
}
Run Code Online (Sandbox Code Playgroud)
代码的使用方式是需要在同一范围内引用所有这些类.可能存在以下情况:
...
Vehicle.Wheel.DoSomething();
Vehicle.Truck.Wheel.DoSomething();
Vehicle.Car.Wheel.DoSomething();
...
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我最好给这些课程更具体的名字
namespace Car{
class CarWheel: Vehicle.Wheel{...} //Car specific Wheel object
...
}
Run Code Online (Sandbox Code Playgroud)
或保留第一个示例中所示的命名,并依赖于命名空间中编码的信息以便清楚起见?在后一种方法下,我假设我想在使用这个库的代码中明确地使用alaising,对吗?
拥有以下内容似乎更令人不满:
Vehicle.Car.CarWheel
Run Code Online (Sandbox Code Playgroud)
要么
Vehicle.Truck.TruckEngine …Run Code Online (Sandbox Code Playgroud)