我有以下课程:
[DataContract]
public class Pair<TKey, TValue> : INotifyPropertyChanged, IDisposable
{
public Pair(TKey key, TValue value)
{
Key = key;
Value = value;
}
#region Properties
[DataMember]
public TKey Key
{
get
{ return m_key; }
set
{
m_key = value;
OnPropertyChanged("Key");
}
}
[DataMember]
public TValue Value
{
get { return m_value; }
set
{
m_value = value;
OnPropertyChanged("Value");
}
}
#endregion
#region Fields
private TKey m_key;
private TValue m_value;
#endregion
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
protected void …
Run Code Online (Sandbox Code Playgroud) 我正在开发WPF应用程序,我想重用我在所有这些应用程序中相同的类,所以我可以添加它们作为参考.
在我的情况下,我有一个我的命令类:
public class RelayCommand : ICommand
{
#region Fields
readonly Action<object> _execute;
readonly Predicate<object> _canExecute;
#endregion // Fields
#region Constructors
public RelayCommand(Action<object> execute)
: this(execute, null)
{
}
public RelayCommand(Action<object> execute, Predicate<object> canExecute)
{
if (execute == null)
throw new ArgumentNullException("execute");
_execute = execute;
_canExecute = canExecute;
}
#endregion // Constructors
#region ICommand Members
public bool CanExecute(object parameter)
{
return _canExecute == null ? true : _canExecute(parameter);
}
public event EventHandler CanExecuteChanged
{
add { CommandManager.RequerySuggested += value; } …
Run Code Online (Sandbox Code Playgroud) 我想知道是否有办法制作#region Some Region #endregion Some Region
.如果没有办法做到这一点那么也许Resharper可能吗?
希望很清楚我在这里想要实现的目标.
编辑:
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>#region</Title>
<Shortcut>#region</Shortcut>
<Description>Code snippet for #region</Description>
<Author>Microsoft Corporation</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
<SnippetType>SurroundsWith</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>name</ID>
<ToolTip>Region name</ToolTip>
<Default>MyRegion</Default>
</Literal>
</Declarations>
<Code Language="csharp"><![CDATA[#region $name$
$selected$ $end$
#endregion $name$]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
Run Code Online (Sandbox Code Playgroud)
第二次编辑: 它是有效的,但只有当我制作插入片段时.从intellisense这使用其他一些片段我猜.
那么有没有办法从intellisense添加我的区域而不是插入片段菜单?
我们有一个基于WPF .NET 4.0 C#的应用程序.我们从XML定义(而不是XAML)构建了我们的用户界面,但在下面我们使用WPF来呈现UI.那是在运行时,我们根据XML定义创建WPF UI.
我们在标签导航方面遇到了问题.我们为文本和组合框控件设置TabStop,TabIndex.
但是标签导航无效.如何使标签导航适用于此布局?
这是XAML标记:
<ScrollViewer Grid.Column="1" Grid.Row="2" HorizontalScrollBarVisibility="Disabled" Width="990">
<StackPanel Margin="50 0 0 40">
<ItemsControl x:Name="streamList" ItemsSource="{Binding StreamInformations}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Margin="10" Orientation="Horizontal" >
<StackPanel Orientation="Horizontal">
<Image Source="{Binding ImageUrl}" Height="60" />
<StackPanel Margin="10 0 0 0" VerticalAlignment="Center">
<TextBlock Foreground="Black" Text="{Binding ChannelName}" FontSize="12" />
<TextBlock Foreground="#999" Text="{Binding PlayerName}" FontSize="10" />
<TextBlock Foreground="#999" Text="{Binding ViewCount}" FontSize="10" />
</StackPanel>
</StackPanel>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</ScrollViewer>
Run Code Online (Sandbox Code Playgroud)
这就是它的样子:
我希望这些项目水平显示并在到达StackPanel边缘时向下流动.
目前看来,我的DataContext集合中的每个项目都在创建自己的StackPanel,所以这不是我想要的.
有什么建议?
将此问题减少到最低限度,请考虑此MarkupExtension类...
public class ProblemStatement : MarkupExtension
{
private readonly string _first;
private readonly string _second;
public ProblemStatement(string first, string second)
{
_first = first;
_second = second;
}
public override object ProvideValue(IServiceProvider serviceProvider)
{
return this;
}
public override string ToString()
{
return _first + _second;
}
}
Run Code Online (Sandbox Code Playgroud)
宣布这个Xaml时......
<Grid>
<TextBlock Name="TextBlock1" Tag="{so:ProblemStatement 'hello', 'world'}"/>
<TextBlock Text="{Binding ElementName=TextBlock1, Path=Tag}"/>
</Grid>
Run Code Online (Sandbox Code Playgroud)
...你按预期在TextBlock中看到' helloworld '.一切都很顺利.
但是将构造函数参数更改为此...
public ProblemStatement(string first, string second = "nothing")
Run Code Online (Sandbox Code Playgroud)
......以及相关的Xaml ......
<Grid>
<TextBlock Name="TextBlock1" Tag="{so:ProblemStatement 'hello'}"/>
<TextBlock Text="{Binding …
Run Code Online (Sandbox Code Playgroud) 在xaml编辑器中是否有可能替换特定的标记,以便它自动替换相应的结束标记?
我目前的工作流程
我从这个xaml代码开始:
<StackPanel>
<Button />
</StackPanel>
Run Code Online (Sandbox Code Playgroud)
然后,我改变主意,喜欢使用WrapPanel ..
<WrapPanel>
<Button />
</StackPanel>
Run Code Online (Sandbox Code Playgroud)
然后,我必须向下滚动到stackpanel结束标记并替换它...
<WrapPanel>
<Button />
</WrapPanel>
Run Code Online (Sandbox Code Playgroud)
- >完了
是否可以在一次操作中完成最后两个步骤?像c#代码中的重命名重构一样有用......
我想将Expander按钮放在标签的右侧.这该怎么做?
我在这段代码的第三行有一个例外"第二个路径片段不能是驱动器或UNC名称"
DirectoryInfo labdi = new DirectoryInfo(Back.mainfolderpath + @"\news\l");
DirectoryInfo tld = new DirectoryInfo(labdi.FullName + @"\" + NorA.sn.labl[i]);
tld = labdi.CreateSubdirectory(labdi.FullName + @"\" + NorA.sn.labl[i] + @"\");
Run Code Online (Sandbox Code Playgroud)
网上没有有用的方法.谢谢.:!
我有一个困扰我现在几天的问题.我曾试图谷歌这个问题,但到目前为止还没有找到任何解决方案,甚至没有一个人有同样的问题.
似乎C#方法System.Buffer.BlockCopy给你留下了某种内存鬼.我有这样的方法:
private float[,] readFloatArray2 (byte[] b) {
int floatSize = sizeof(float);
float[,] v = new float[2, (b.Length / 2) / floatSize];
System.Buffer.BlockCopy(b, 0, v, 0, b.Length);
return v;
}
Run Code Online (Sandbox Code Playgroud)
将字节数组转换为2D浮点数组.先前从流中读取数据.我已将问题定位为System.Buffer.BlockCopy方法.
如果我删除BlockCopy命令,应用程序使用的内存将是一半大小.这意味着字节数组仍然存在并不是我的错.因为没有BlockCopy命令,字节数组正常死亡.无论如何都会创建float数组(包含或不包含复制的信息).
我不太确定这是否是BlockCopy命令或GC的问题,因为我还试图调用System.GC.Collect(); 在BlockCopy之后,它也完美无缺(我知道你不应该这样做......这就是为什么我在这里要求建议).
我也不会打扰,但问题涉及几百兆.
除了内存问题,该方法工作得很好.有谁知道导致内存问题的原因是什么?
问候和提前感谢oli
ps:我使用.NET4.0与Visual Studio 2010 PRO和WIN7 ...不知道这是否相关.
c# ×7
wpf ×7
xaml ×4
.net ×3
buffer ×1
command ×1
controls ×1
datatemplate ×1
directory ×1
expander ×1
itemscontrol ×1
memory-leaks ×1
mvvm ×1
navigation ×1
panel ×1
resharper ×1
sorting ×1
subdirectory ×1
wpf-controls ×1