假设我有这个(C++或C)代码:
vector<int> my_vector;
for (int i = 0; i < my_vector.size(); i++) {
my_vector[i] = 0;
}
Run Code Online (Sandbox Code Playgroud)
我不在乎它是否做得对.重要的部分是for循环声明.编译器为此提供了有符号/无符号的不匹配,因为size()返回unsigned int而不是signed符号.i改为无签名有多重要?我将循环计数器声称为习惯中的int,但如果这是一个潜在的错误,我会强迫自己摆脱这种习惯.
我有这个简单的XAML示例:
<Window x:Class="DynTemplateTest.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>
<DataTemplate x:Key="ItemTemplate">
<ItemsControl ItemsSource="{Binding}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Rectangle Width="30" Height="30" Fill="Red"></Rectangle>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemContainerStyle>
<Style>
<Setter Property="Canvas.Left" Value="{Binding Position}"></Setter>
</Style>
</ItemsControl.ItemContainerStyle>
</ItemsControl>
</DataTemplate>
</Window.Resources>
<DockPanel LastChildFill="True">
<ContentPresenter
Content="{Binding Path=Items}"
ContentTemplate="{StaticResource ItemTemplate}"
>
</ContentPresenter>
</DockPanel>
</Window>
Run Code Online (Sandbox Code Playgroud)
它以MVVM样式呈现我的可观察集合中的项目.每个项目在属性中具有水平位置.每个项目还有一个属性IsSpecial,它告诉它是否要以某种特殊方式呈现.我希望普通项目(IsSpecial = false)呈现为红色方块(已在代码中),特殊项目为蓝色圆圈,内部带有"特殊"文本.
我不知道的是如何调整XAML代码来为项目进行模板选择.有没有办法在不编码我自己的ItemTemplateSelector的情况下做到这一点?它是否仍然适用于基于绑定的画布定位.我认为解决方案是将项目模板提取到一个单独的模板,为特殊项目再创建一个模板,然后以某种方式使用触发器...但对我来说这并不容易,因为我现在是WPF初学者.
另一件事是我非常不喜欢将Position传递给项目的方式.还有其他方法吗?
有没有其他建议如何改进代码?
我有一个带有工厂模式功能的类:
abstract class ParentObj {
public function __construct(){ ... }
public static function factory(){
//returns new instance
}
}
Run Code Online (Sandbox Code Playgroud)
我需要子项能够调用工厂函数并返回调用类的实例:$child = Child::factory();并且最好不要覆盖子类中的工厂函数.
我尝试了多种不同的方法来实现这一点无济于事.我宁愿远离使用反射的解决方案,比如__CLASS__.
(如果重要,我使用的是PHP 5.2.5)
好吧,我有这个以前从未有过的问题,这真的让我烦恼.
基本上我正在尝试使用表单将文本提交到文本字段.出于某种原因,当我提交原始文本和完全停止时它只能正常工作,但似乎有一个像'或'的标点符号!在textarea然后它只是不会提交到数据库.没有显示错误,但没有结果.
这显然是一个非常明显的问题,我错过了,因为我很蠢,有什么想法吗?
您建议使用哪些项目协作工具来维护任务,错误,协作,消息传递,存储文件,维基等?
我看了一下Remember the Milk,但不确定它是否理想!背包看起来很好,价格合理; 有人用过吗?
从这个答案:什么是C++终止处理程序右Thing(TM)?
当应用程序退出时,操作系统会自动清理"是"和"不"的资源列表会很不错.在您的回答中,如果您可以指定操作系统/资源并且最好是指向某个文档(如果适用)的链接,那将是很好的.
显而易见的一个:
内存:是自动清理.题.有没有例外?
我尝试使用domainpeople.com API,我需要使用XML.
目前我有一个错误说"找不到apiProtocol"我想那时我的Xml文档格式不正确.
发送的当前xml是:
<apiProtocol version="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNameSpaceSchemaLocation="checkrequest.xsd">
<checkRequest user="ifuzion" password="fish4gold121" reference="123456789">
<domain name="google.com" />
</checkRequest>
</apiProtocol>
Run Code Online (Sandbox Code Playgroud)
显然这<?xml?>部分不会打印出来.
我的代码基本上类似于:
XDocument xDocument = new XDocument(
new XDeclaration("1.0", "UTF-8", "yes"),
new XElement("Books"));
Run Code Online (Sandbox Code Playgroud)
(我删除了我的代码以获得简单的问题,但结构完全相似).
XDocument没有打印出<?xml?>部件的原因是什么?似乎使用XmlDocument它可以工作但不能与XDocument ...任何提示?
假设我想设置一个通用的complexType,如下所示:
<xs:complexType name="button">
<xs:sequence>
<xs:element name="id" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="href" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="label" type="xs:string" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
Run Code Online (Sandbox Code Playgroud)
我想在我的模式文件中的各个地方引用complexType,如下所示:
<xs:element name="someButton" type="button" />
Run Code Online (Sandbox Code Playgroud)
我可以通过someButton元素为按钮子元素设置默认值吗?(即如果我想someButton的默认标签为"Go"或默认的href为"index.html")
基本上......现在我有类似的东西
<Field Name="State" DataSourceField="State" />
Run Code Online (Sandbox Code Playgroud)
我试图以尽可能简单的方式删除冗余.
我很高兴看到最新版本的decoratorpython模块(3.0).与以前的迭代相比,它看起来更清晰(例如语法比以前更加含糖).
然而,对于那些自己提出论点的装饰者来说,它似乎有糟糕的支持(例如"酸"语法,可怕地延伸隐喻).有没有人有一个很好的例子说明你如何使用decorator3.0 干净利落地做到这一点?
def substitute_args(fun, arg_sub_dict):
def wrapper(arg):
new_arg = arg_sub_dict.get(arg, arg)
return fun(new_arg)
# some magic happens here to make sure that type signature,
# __name__, __doc__, etc. of wrapper matches fun
return wrapper
Run Code Online (Sandbox Code Playgroud)