在.Net4.5中,我发现了结果
System.Text.RegularExpressions.Regex.IsMatch(
"00000000000000000000000000000", "^[1-9]|0$")
Run Code Online (Sandbox Code Playgroud)
是真的.
我期望的结果是错误的.我不知道为什么.你能帮助我吗?
更新:开始时,我正在验证^-?[1-9]\d*|0$
用于匹配互联网上找到的整数的正则表达式,我发现多个字符串与0
正则表达式匹配.
我在Window的右边设置了一个ContentControl,并设置了内容绑定项(它的类型是ObservableCollection).现在我想实现它:如果没有项目,ContentControl选择第一个DataTemplate,并将项目添加到项目中,ContentControl将选择第二个DataTemplate来显示一些信息.
像这样:
问题是当我在项目中添加一个项目时,ContentControl没有更新和更改DataTemplate,我尝试设置模式,UpdateSourceTrigger等,但失败了.在ViewModel中,删除一个项目后,我使用这个语句,它将很好地工作<1>:
private void ExecuteDeleteClientCommand()
{
...
if (DeleteClient(item))
{
ObservableCollection<MyViewModel> tmp = TabItems;
TabItems = null;
TabItems = tmp;
}
}
Run Code Online (Sandbox Code Playgroud)
.
<ContentControl
ContentTemplateSelector="{StaticResource MyDataTemplateSelector}"
Content="{Binding Items}"/>
Run Code Online (Sandbox Code Playgroud)
.
public class SingleClientDataTemplateSelector : DataTemplateSelector
{
public override DataTemplate SelectTemplate(object item,
DependencyObject container)
{
ObservableCollection<MyViewModel> obj =
item as ObservableCollection<MyViewModel>;
if (null == obj || 0 == obj.Count)
{
return App.Current.FindResource("NullItemDataTemplate") as DataTemplate;
}
return App.Current.FindResource("DefaultDataTemplate") as DataTemplate;
}
}
Run Code Online (Sandbox Code Playgroud)
编辑: 使用这种方式删除一项后也失败:
RaisePropertyChanging(ItemsPropertyName);
RaisePropertyChanged(ItemsPropertyName);
Run Code Online (Sandbox Code Playgroud)
但我想知道为什么它适用于<1>.
编辑2 …
在 WPF 中,我想在 Window 的标题栏中/上方添加一个 userControl,如下所示:
红色部分是UserControl,绿色部分是标题栏。
现在我希望得到你的一些建议。需要扩展 Window 类还是只自定义 Window 的样式?最好提供源代码。
我设计的过程是:
当我添加语句"self.editing = YES;"时 在 - (void)viewDidLoad方法中,它会崩溃.
我发现它没有执行"tableView:cellForRowAtIndexPath:"方法.但是,实际上我相信通过NSLog()的结果在第0节中有1行.
如果我不添加"self.editing = YES;",它会正确运行.
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationItem.rightBarButtonItem = self.editButtonItem;
self.editing = YES; // here: adding it cause crash
}
Run Code Online (Sandbox Code Playgroud)
执行"insertRowsAtIndexPaths:withRowAnimation:"后,它崩溃了.两个声明:
[self.tableView beginUpdates];
[self.tableView endUpdates];
Run Code Online (Sandbox Code Playgroud)
添加或不添加,所有cuase崩溃.
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
[super setEditing:editing animated:animated];
[self.tableView beginUpdates];
NSInteger booksCount = self.course.books.count;
NSArray *booksInsertIndexPath = [NSArray arrayWithObject:[NSIndexPath indexPathForRow:booksCount inSection:0]];
if (editing) {
[self.tableView insertRowsAtIndexPaths:booksInsertIndexPath
withRowAnimation:UITableViewRowAnimationBottom]; // then, it crashes
} else {
[self.tableView deleteRowsAtIndexPaths:booksInsertIndexPath
withRowAnimation:UITableViewRowAnimationBottom];
}
[self.tableView endUpdates]; …
Run Code Online (Sandbox Code Playgroud) 我刚开始学习WPF,所以我不熟悉样式和模板.我想CheckBox
用a Image
和2 Labels
这样定制一个:
我能怎么做?
的.xaml
<Window x:Class="WpfApplication4.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<StackPanel>
<CheckBox Width="150"
Height="40"
Margin="4"
Padding="4,0,0,0">
<Grid Background="#FFEEEEEE"
Width="130"
MaxWidth="Infinity">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Image Grid.Row="0"
Grid.RowSpan="2"
Grid.Column="0"
Margin="5"
Source="/WpfApplication4;component/Images/LargeIcon.png" />
<Label Grid.Row="0"
Grid.Column="1"
Padding="0">
Label1
</Label>
<Label Grid.Row="1"
Grid.Column="1"
Padding="0">
Label2
</Label>
</Grid>
</CheckBox>
</StackPanel>
</Window>
Run Code Online (Sandbox Code Playgroud)
编辑:
的.xaml
<Application x:Class="WpfApplication4.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2006"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
StartupUri="MainWindow.xaml">
<Application.Resources>
<Style x:Key="MyCheckBox"
TargetType="{x:Type CheckBox}">
<Setter Property="Width" Value="150"/> …
Run Code Online (Sandbox Code Playgroud)