我在我的控件库中的几个类上设置ToolboxItem(false)属性,以防止将其添加到Toolbox.此属性与ASP.NET设计器完美配合,但使用WPF设计器似乎没有任何效果.
是否有其他方法可以使用WPF实现此功能,或者只是不受支持?
我最近开始了一个新项目,并且我试图将我的实例变量始终初始化为某个值,因此它们都不会在任何时候为null.以下小例子:
public class ItemManager {
ItemMaster itemMaster;
List<ItemComponentManager> components;
ItemManager() {
itemMaster = new ItemMaster();
components = new ArrayList<ItemComponentManager>();
}
...
}
Run Code Online (Sandbox Code Playgroud)
重点是在代码中的某个地方使用实例变量之前避免繁琐的null检查.到目前为止,它工作正常,你大多不需要null值,因为你也可以检查空字符串或空列表等.我没有使用这种方法的方法范围变量,因为它们的范围非常有限,所以不会影响代码的其他部分.
这一切都是实验性的,所以我想知道这种方法是否有效,或者是否有一些我还没有看到的陷阱.保持实例变量初始化通常是一个好主意吗?
有没有什么方法可以组合谓词?
让我们说我有这样的事情:
class MatchBeginning : public binary_function<CStdString, CStdString, bool>
{ public:
bool operator()(const CStdString &inputOne, const CStdString &inputTwo) const
{ return inputOne.substr(0, inputTwo.length()).compare(inputTwo) == 0; }
};
int main(int argc, char* argv[])
{
CStdString myString("foo -b ar -t az");
vector<CStdString> tokens;
// splits the string every time it encounters a "-"
split(myString, tokens, "-", true, true);
vector<CStdString>::iterator searchResult = find_if(tokens.begin(), tokens.end(), not1(bind2nd(MatchBeginning(), "-")));
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这有效,但现在我想做一些事情:
searchResult = find_if(tokens.begin(), tokens.end(), bind2nd(MatchBeginning(), "-b") || not1(bind2nd(MatchBeginning(), "-")));
Run Code Online (Sandbox Code Playgroud)
所以我想找到第一个以"-b"开头的字符串或第一个不以" - "开头的字符串.但是,这给了我一个错误(二进制'||'未定义).
有没有办法做到这一点?
我有一个高300的root UserControl.
在里面,我有一个边框,我想扩展到自己的控件的大小,所以如果我堆叠更多的控件,它将扩展 - 更少的控件,它将收缩.
但是,当我将其设置为"Auto"时,它会将其扩展为其父容器的大小,而不是其子控件的大小.
如何让Border扩展和缩小到其子控件的大小,比如HTML表的功能?
<UserControl x:Class="Second105.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:basics="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
Width="400" Height="300">
<Grid x:Name="LayoutRoot" Background="White">
<Border
Background="Tan"
CornerRadius="10"
Padding="10"
Width="300"
Height="Auto">
<StackPanel>
<TextBlock HorizontalAlignment="Center" Margin="0 0 0 5">Please select a <Run FontStyle="Italic">week day</Run>:</TextBlock>
<basics:Calendar
Name="theCalendar"
SelectedDatesChanged="Calendar_SelectedDatesChanged"/>
<TextBlock
Name="theMessage"
Margin="0 10 0 0"
HorizontalAlignment="Center"
Text="..."/>
</StackPanel>
</Border>
</Grid>
</UserControl>
Run Code Online (Sandbox Code Playgroud) 我正在学习Objective-c但是想在Windows上通过某种模拟器运行代码片段 - 最好是基于Web的.
我想了解Objective-C语法并浏览常见的代码示例,可能是通过某种控制台.我可能会留下任何框架类型学习,当我进入我的MacBook,在家里.
我做了一个快速的谷歌没有成功.
我正在使用基类构造函数作为工厂并在此构造函数/工厂中更改类以选择适当的类 - 这种方法是很好的python实践还是有更优雅的方法?
我试图阅读有关元类的帮助,但没有取得很大的成功.
这是我正在做的事情的例子.
class Project(object):
"Base class and factory."
def __init__(self, url):
if is_url_local(url):
self.__class__ = ProjectLocal
else:
self.__class__ = ProjectRemote
self.url = url
class ProjectLocal(Project):
def do_something(self):
# do the stuff locally in the dir pointed by self.url
class ProjectRemote(Project):
def do_something(self):
# do the stuff communicating with remote server pointed by self.url
Run Code Online (Sandbox Code Playgroud)
有了这段代码,我可以通过基类Project创建ProjectLocal/ProjectRemote的实例:
project = Project('http://example.com')
project.do_something()
Run Code Online (Sandbox Code Playgroud)
我知道另一种方法是使用将返回基于url的类对象的fabric函数,然后代码看起来类似:
def project_factory(url):
if is_url_local(url):
return ProjectLocal(url)
else:
return ProjectRemote(url)
project = project_factory(url)
project.do_something()
Run Code Online (Sandbox Code Playgroud)
我的第一种方法是品味问题还是有一些隐藏的陷阱?
我有两个或更多数组 - 一个有ID,一个或多个有字符串值.我想将这些合并到一个哈希表中,以便我可以按ID查找值.
以下函数可以完成这项工作,但更短更甜的版本(LINQ?)会很好:
Dictionary<int, string[]> MergeArrays( IEnumerable<int> idCollection,
params IEnumerable<string>[] valueCollections )
{
var dict = new Dictionary<int, string[]>();
var idL = idCollection.Count();
while ( idL-- > 0 )
{
dict[idCollection.ElementAt( idL )] = new string[valueCollections.Length];
var vL = valueCollections.Length;
while ( vL-- > 0 )
dict[idCollection.ElementAt( idL )][vL] = valueCollections[vL].ElementAt( idL );
}
return dict;
}
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
我已将文件和数据库从BradPPresents.com复制到BradP.com.
由于"漂亮的URL"由joomla!启用,因此需要.htaccess文件才能正确显示页面.
您可以看到数据库和所有连接都在http://bradp.com/index.php上运行,但http://bradp.com/home.html不起作用,因为它依赖于.htaccess文件来解析URL.
我将相同的htaccess文件从bradppresents.com(当前工作正常)复制到bradp.com,当文件存在时我收到"内部服务器错误".一旦删除,错误就会消失,但当然网站不能按需运行.
我希望有人可以为我照亮一点.
这是.htaccess文件
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} (/|\.htm|\.php|\.html|\.aspx|\.asp|/[^.]*)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php
## This attempts to block the most common type of exploit `attempts` to Joomla!
#
# Block out any script trying to set a mosConfig value through the URL
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
# Block out any script trying to base64_encode crap to send via URL
RewriteCond %{QUERY_STRING} base64_encode.*\(.*\) …Run Code Online (Sandbox Code Playgroud) 我正在寻找一种使用C#或其他.NET语言查找进程树(如Process Explorer之类的工具所示)的简便方法。查找另一个进程的命令行参数也很有用(System.Diagnostics.Process上的StartInfo似乎对当前进程以外的其他进程无效)。
我认为这些事情只能通过调用win32 api来完成,但是我很高兴被证明是错误的。