我是否在从.net 3.5到.net 4的步骤中遗漏了一些东西,因为我看到看似错误的行为似乎与系统的目标背道而驰.
我正在尝试使用一些示例来创建一个简单的MVVM库.我正在Twitter客户端应用程序中使用它进行一些额外的学习,并且遇到了一个很大的障碍.
情景是这样的.我的根ViewModel(TwitterClientViewModel)对象被赋予一个DialogViewModel对象的实例以供显示.DialogViewModel添加到集合中,bool HasDialogs设置为true.如有必要,将为集合和标志调用PropertyChanged事件.这部分工作非常棒.
TwitterClientViewModel的视图称为TwitterClientTemplate,并使Visible成为DialogViewTemplate(DialogViewModel的视图)托管的叠加层.托管ContentControl的模板引用了带有DynamicResource扩展的DialogViewTemplate.这在设计人员和运行时都很有用.
这是事情变得奇怪的地方.DialogViewTemplate的"主体"使用绑定到DialogViewModel.Content(类型对象)的其他内容控件来托管对话框内容.希望是使用TemplateSelector(我编写了一个很好的声明式的,但已经注释用于测试目的)我可以显示文本和交互元素.例如,在验证Twitter帐户时向用户请求详细信息.在这种情况下,PIN码.
此时,我有两个嵌套的内容控件用于对话框实现.出于测试目的,DialogViewTemplate正文中的contentcontrol使用staticresource扩展来检索EnterPINDialogTemplate(EnterPINDialogViewModel的视图).EnterPINDialogTemplate和DialogViewTemplate都在同一个文件中(前者当然是先定义的)虽然最初它们是分开的.
在运行时,staticresource扩展会抛出带有消息的XamlParseException; '为'System.Windows.Markup.StaticResourceHolder'提供价值,引发了一个异常.
和内部异常消息;
'找不到名为'EnterPINDialogTemplate'的资源.资源名称区分大小写'
使用dynamicresource返回null并在contentcontrol中显示EnterPINDialogViewModel类型的全名 - 正如资源未解析时所预期的那样.在调用FrameWorkElement.FindResource()时突破我的自定义TemplateSelector会抛出类似的异常(TryFindResource返回null).
我的第一个想法是在构建datatemplate时逻辑树被拆分,我记得早期项目中该区域的问题.我尝试使用ResourceDictionary的MergeDictionaries属性使资源字典可以在DataTemplate中使用,但设计者不喜欢这一点,这里描述了错误:http: //connect.microsoft.com/VisualStudio/feedback/details/498844/WPF的设计师抛出,InvalidCastException的
抓住那个想法.我尝试在Application,Window和TwitterClientTemplate级别合并字典,但没有运气.
以下是xaml文件.
DialogTemplates.xaml
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:VM="clr-namespace:EpicTweet.ViewModel"
xmlns:ET="clr-namespace:EpicTweet"
xmlns:T="clr-namespace:EpicTweet.Tools"
xmlns:MV="clr-namespace:MVVM;assembly=MVVM"
xmlns:Loc="clr-namespace:EpicTweet.Localization"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d">
<DataTemplate DataType="VM:EnterPINDialogViewModel" x:Key="EnterPINDialogTemplate">
<Grid d:DesignWidth="453.89" d:DesignHeight="78.92" Loc:ResXManagerProperty.ResourceManager="{x:Static ET:Language.ResourceManager}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Label Content="{Loc:ResxExtension ResourceName=String_PIN, FallbackValue='<PIN>'}"/>
<TextBox Grid.Column="1"/>
<TextBlock Grid.Row="1" Grid.RowSpan="2"></TextBlock>
</Grid>
</DataTemplate>
<DataTemplate x:Key="DialogViewTemplate" DataType="MV:DialogViewModel">
<Border BorderBrush="Black" BorderThickness="1">
<Grid d:DesignWidth="277.419" d:DesignHeight="74.96" Background="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}" Height="Auto" Width="Auto">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/> …Run Code Online (Sandbox Code Playgroud) 对于我的身份验证模型,我想确保同一封电子邮件不可能多次注册.我是nHibernate和部分LINQ的新手,所以我问这是否足够"检查"以确保发生这种情况.
public MembershipCreateStatus CreateUser(string email, string password)
{
if (String.IsNullOrEmpty(email)) throw new ArgumentException("Value cannot be null or empty.", "userName");
if (String.IsNullOrEmpty(password)) throw new ArgumentException("Value cannot be null or empty.", "password");
using (var session = sessionFactory.OpenSession())
{
using (var transaction = session.BeginTransaction())
{
var members = session.CreateCriteria<Member>().List<Member>();
// determine is the email address already exists in the database
if (members.Any(i => i.Email == email))
return MembershipCreateStatus.DuplicateEmail;
// create the new member, if they are valid
var member = new Member { …Run Code Online (Sandbox Code Playgroud) 创建一个自定义异常是一个好主意,当应用程序逻辑失败时会抛出这个异常,而这个异常会被处理掉吗?
我想,最好还是返回一个对象或一个值; 但:
如果没有,那么在我们的代码中引入一些自定义异常的正确条件是什么?
谢谢!
我有一个表行,在表格行的任何地方都有鼠标点击附加的Javascript操作:
<tr onmousedown="someAction(this)">
<td>cell 1</td>
<td>cell 2</td>
<td><a href="page2.html">cell 3</a></td>
</tr>
Run Code Online (Sandbox Code Playgroud)
如果用户点击该行中的任何位置,我希望遵循Javascript操作someAction(this).但是,如果用户单击指向page2的链接,那么我希望忽略该操作并遵循链接.
不幸的是,首先会观察到该动作,这恰好会使链接文本的位置移动到足以使点击被删除.换句话说,在这种情况下,用户实际上无法点击链接并转到第2页.
如何禁用链接点击的mousedown操作?
谢谢!
更新: 基于答案,我最终在HTML的末尾包含了以下JavaScript,它按照建议注册了一个停止传播的事件处理程序,如下所示:
...
<script type="text/javascript" language="javascript">
//<![CDATA[
function stopEvent(ev) {
ev.stopPropagation();
}
var links = document.getElementsByTagName('a');
for (var i = 0; i < links.length; i++) {
links[i].addEventListener("onmousedown", stopEvent, false);
}
//]]>
</html>
Run Code Online (Sandbox Code Playgroud)
这可能很容易被包含在文档的onload事件中,但CDATA部分已经因其他原因而被要求,所以我在这里添加了我需要的内容.
感谢所有的帮助和好建议!:)
使用Java和IntelliJ在OSX上开发程序.处理网络套接字和ICMP.因此,程序需要在OSX上以root用户身份运行或sudo'd.程序在sudo下的IntelliJ外的终端窗口运行正常.但是,我想从IntelliJ(V9)调试并运行它.在IntelliJ中它出错(我需要root privs来枚举网络设备).我知道如何在IntelliJ中传递程序和VM参数但是现在如何点击Run和/ Debug并让它在sudo下运行?所需要的基本上是sudo java ...... MyProgram而不是java ..... MyProgram任何想法或解决方法.
我需要一个很好的方法来询问一个数组/矩阵值,但是为越界索引报告一个默认值(0):
如果第二个索引长度是3,b [2] [4]应该返回0,并且
b [-1] [2]
我也检查了这一点:
在Python中获取索引超出范围的默认值,但在我看来它对负索引不起作用 - 因为python总是将数组长度添加到它们(是的? )
我正沿着超载的思路__getitem__,但我只是来蟒蛇1个月前,我不那么熟练...
任何帮助赞赏!
亚历山德罗
在magento中如何从其产品ID获取每个产品的类别ID.
$items = $request->getAllItems();
$c = count($items);
for ($i = 0; $i < $c; $i++) {
if ($items[$i]->getProduct() instanceof Mage_Catalog_Model_Product) {
if ($items[$i]->getProduct()->getId()) {
$this->_dhlAllowed = false;
}
}
}
Run Code Online (Sandbox Code Playgroud)
这里$items[$i]->getProduct()->getId()返回产品ID.我想要它的类别ID.
我正在使用Qt 4.7 QPainter将一些多边形等绘制到一个小部件中.我希望改变坐标系,使得(0,0)位于我的小部件的中心,并且x/y轴以标准的"笛卡尔"方式运行(即,y增加"向上"并且减少"下").换句话说,如果你知道我的意思,我希望坐标是"数学" - 而不是"计算机图形".:-)
我正在尝试使用setViewport()和setWindow()而不是自己做数学,因为能够直接用我的坐标调用draw方法会很好.
这是我到目前为止所得到的:
// Setup coordinates
double screenWidth = width();
double screenHeight = height();
double windowWidth = 100.0;
double windowHeight = (screenHeight / screenWidth) * windowWidth;
painter.setViewport(0, 0, screenWidth, screenHeight);
painter.setWindow(-(windowWidth / 2.0), -(windowHeight / 2.0), windowWidth, windowHeight);
// Draw stuff
painter.setPen(Qt::NoPen);
painter.setBrush(Qt::blue);
painter.drawRect(-10, -10, 20, 20);
Run Code Online (Sandbox Code Playgroud)
现在这个工作得很好,因为它在屏幕中间绘制了一个漂亮的蓝色方块.问题是,我不得不说左上角是(-10,-10).我希望能够制作它(-10,10),因为它就像笛卡尔坐标一样.
我试着搞乱setWindow/setViewport以获得这个"y轴翻转",但无济于事.这似乎是一个非常容易/基本的事情,但在搜索Qt文档和网络后,我无法弄明白!
谢谢,
克里斯
是否可以在Java中执行以下C#代码?
Process.Start("c:/test.exe", "filearg1,filearg2,filearg3");
Run Code Online (Sandbox Code Playgroud) var range = getDates(new Date(), new Date().addDays(7));
Run Code Online (Sandbox Code Playgroud)
我希望"range"是一个日期对象数组,两个日期之间每天一个.
诀窍是它应该处理月和年的边界.
谢谢.
c# ×3
javascript ×2
.net ×1
arguments ×1
arrays ×1
c++ ×1
coordinates ×1
datatemplate ×1
date ×1
date-range ×1
datetime ×1
exception ×1
graphics ×1
java ×1
linq ×1
magento ×1
magento-1.4 ×1
nhibernate ×1
node.js ×1
process ×1
python ×1
qpainter ×1
qt ×1
qt4 ×1
wpf ×1