所以我有一个可观察的集合绑定到ItemsControl.
当我向集合添加项目时,我从Visual集合中获得了超出范围的索引的异常.
<ItemsControl x:Name="ReportPages" ItemsSource="{Binding History}" DockPanel.Dock="Top">
<ItemsControl.Template>
<ControlTemplate TargetType="ItemsControl">
<ItemsPresenter HorizontalAlignment="Center"/>
</ControlTemplate>
</ItemsControl.Template>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<ItemsControl ItemsSource="{Binding ChildWindows}">
<ItemsControl.Template>
<ControlTemplate TargetType="ItemsControl">
<Grid Margin="0,10,0,10" >
<ItemsPresenter />
<Border x:Name="ResizeFrame" BorderThickness="4" BorderBrush="LightBlue" Visibility="{Binding Active, Converter={StaticResource BooleanToVisibilityConverter}}"/>
</Grid>
</ControlTemplate>
</ItemsControl.Template>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas x:Name="LayoutCanvas" Background="white" ClipToBounds="true"
MouseDown="History_MouseLeftButtonDown" PreviewMouseDown="ClosePanels"
Width="{Binding PageSizeProp.PageWidth}" Height="{Binding PageSizeProp.PageHeight}"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
Run Code Online (Sandbox Code Playgroud)
内部ChildWindows是我要添加项目的集合.需要注意的是,ChildWindows是一个ReadOnlyObservableCollection,我通过一个可以访问它所基于的Collection的方法添加.
我完全失去了为什么会发生这种情况(并且只有一些时间).
编辑:这是实际的堆栈跟踪
at System.Windows.Media.VisualCollection.Insert(Int32 index, Visual visual)
at System.Windows.Controls.Panel.addChildren(GeneratorPosition pos, Int32 itemCount)
at System.Windows.Controls.Panel.OnItemsChangedInternal(Object sender, ItemsChangedEventArgs args) …Run Code Online (Sandbox Code Playgroud) 所以我有一个非常简单的刻录安装程序,主要包括.net升级或偶尔包含我们的应用程序需要与之交谈的硬件的驱动程序包.
MSI我们创建支持升级或降级.
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
xmlns:bal="http://schemas.microsoft.com/wix/BalExtension">
<Bundle Name="My App Name" Manufacturer="Company Name" Version="!(bind.packageVersion.MyAPP_MSI)"
IconSourceFile="MyIcon.ico" DisableModify="yes" DisableRemove="yes"
UpgradeCode="{15E598EF-89CE-470B-8CEF-E32C8983DA33}" >
<BootstrapperApplicationRef Id="WixStandardBootstrapperApplication.RtfLicense" >
<bal:WixStandardBootstrapperApplication
LogoFile="$(var.CoreComponents.TargetDir)InstallerGraphics\Bootstrapper_Logo.png"
LicenseFile="$(var.CoreComponents.TargetDir)AppRoot\App License.rtf"
SuppressOptionsUI="yes" />
</BootstrapperApplicationRef>
<Chain>
<PackageGroupRef Id="NetFx451Web"/>
<MsiPackage DisplayName="My full Application Name" Id="MyAPP_MSI" SourceFile="$(var.Installer_MyAppMSI_TargetPath)"
DisplayInternalUI="yes" ForcePerMachine="yes" Visible="yes" />
<MsiPackage DisplayName="My Hardware Driver" Id="Installer_MSI_Driver" SourceFile="$(var.Installer_Driver.TargetPath)"
DisplayInternalUI="yes" ForcePerMachine="yes" Visible="yes" />
</Chain>
</Bundle>
</Wix>
Run Code Online (Sandbox Code Playgroud)
我们通常有测试版,当用户想要从测试版降级到我们的稳定版时,他们不能简单地执行旧的EXE安装程序.他们必须明确地从"添加/删除程序"中删除以前的程序包以安装较旧的Burn EXE.
这不是基于MSI的安装的问题.我们如何回到该功能?
日志
[0CB8:067C][2014-06-23T11:10:04]i001: Burn v3.8.1128.0, Windows v6.1(Build 7601: Service Pack 1), path:\\iop-filesvr\IOP\Builds\Main\8.1.240\IO Practiceware Client Setup.exe, cmdline: '-burn.unelevated BurnPipe.{197B8193-6EFC-4ED0-AF90-DE7205F13E65} {CD23A8AB-520B-4F5D-BCB9-98998C5A1EC0} 2216'
[0CB8:067C][2014-06-23T11:10:04]i000: …Run Code Online (Sandbox Code Playgroud) 所以我有一个网格需要根据VM中的标志来改变它的边距.看起来像datatriggers是处理这个问题的正确方法.
所以我设置了这个:
<Grid x:Name="myGrid" Grid.Row="1" Margin="30,0">
<Grid.Style>
<Style TargetType="Grid">
<Style.Triggers>
<DataTrigger Binding="{Binding UI_Preferences.RightPanelPinned}" Value="true" >
<Setter Property="Margin" value="200" />
</DataTrigger>
<DataTrigger Binding="{Binding UI_Preferences.LeftPanelPinned}" Value="true" >
<Setter Property="Margin" value="200" />
</DataTrigger>
</Style.Triggers>
</Style>
</Grid.Style>
</Grid>
Run Code Online (Sandbox Code Playgroud)
哪个有效,但我无法弄清楚如何单独修改左边距或右边距.
图片可以说出千言万语.
当我爬上可视树时,我看到最后一个父类型为System.Windows.Controls.Pimitives.PopupRoot

但乳清我尝试实际比较那种类型VS抱怨它无效.

所以我有这些类暴露了一组子对象.
我不希望其他类添加或删除集合中的对象,因为我需要连接到子对象中的事件,因此当它们被添加或删除时,我希望能够进行其他处理.但我真的很喜欢内部操纵泛型的简易性.
我提到这是一个WPF应用程序,所以我需要INotifySupport吗?
我能想到的最好的就是这样的.
public class foo : INotifyPropertyChanged
{
protected List<ChildFoo> _Children = new List<ChildFoo>();
public foo()
{
}
public void AddChild(ChildFoo newChild)
{
DoAttachLogic(newChild);
_Children.Add(newChild);
NotifyPropertyChange("Children");
}
public void RemoveChild(ChildFoo oldChild)
{
DoRemoveLogic(oldChild);
_Children.Remove(oldChild);
NotifyPropertyChange("Children");
}
public ChildFoo[] Children
{
get
{
return _Children.ToArray();
}
}
}
Run Code Online (Sandbox Code Playgroud)
我没有看到这种设计存在严重缺陷吗?
每次访问Children属性时,我们都会将列表转换为数组.
对此的任何建议都会很棒.
当您进入Windows 7的屏幕分辨率控制面板时,监视器会列出数字,并且有一个标识按钮,使ID出现在两个显示屏上。
有没有办法通过win32 API做到这一点?
所以我在过去6年左右的时间里一直在使用C#进行编程,现在我已经厌倦了VB.net.
我正在使用的代码库使用了一些模块.对我来说,模块看起来很像单身人士.只有一个存在; 它可以在命名空间内的任何地方调用.
这里有什么我想念的吗?VB不支持单例结构的正常方式(私有构造函数/公共实例字段)吗?
因此,目前我正在创建一个1000x1000位图,它只需要花费大约0.3秒来调用Bitmap.SetPixel()函数.
我实际上只绘制了50%的像素,所以它更像是500,000调用setpixel.虽然这确实看起来像很多电话,但是OTOH视频游戏做得更多并且推动了更多像素(其中一些是在程序上生成的).
显然Bitmap.SetPixel并没有针对速度进行优化,但是如果我需要每秒更新一次位图20-30次以获得不错的动画效果,这种方式会变慢,那么我的选择是什么呢?
所以当我尝试发布网站时遇到问题.我在visual studio 2008 sp1.
我有一堆用户控件,在几页上我以编程方式使用它们.
我在aspx页面上有一个参考
<%@ Reference Control="~/UserControls/Foo.ascx" %>
Run Code Online (Sandbox Code Playgroud)
然后在我使用的代码behing上
ASP.usercontrols_foo newFoo control = (ASP.usercontrols_foo)Page.LoadControl("~/UserControls/Foo.ascx");
Run Code Online (Sandbox Code Playgroud)
如果我导航到页面它工作正常,但当我转到发布网站时,我得到一个编译时错误.
我按照这里的教程:http://www.codeproject.com/KB/library/driver-install-with-wix.aspx,但它似乎似乎不想工作 - DPInstexe似乎从未真正运行过?所有文件都正确放置 - 我甚至注意到在教程中他们错过了一个引用.
我的自定义操作如下所示:
<CustomAction Id='Install_M2_Driver'
Execute='deferred' Directory='DRIVER_ROOT'
ExeCommand='"[dirDpInst]DPInst.exe" /SA /PATH "[dirM2]"'
Return='ignore' />
Run Code Online (Sandbox Code Playgroud)
我甚至尝试DPInst.exe使用一个简单的exe来替换回到我身上的参数,一切看起来都不错,如果我实际上从命令行运行命令,而echo消息框已经启动它会调出DPInst安装GUI.
因此有一种NaN方法,但除以零会产生无穷大或负无穷大.
Infinity有一种方法(也是正无穷大和负无穷大).
我想要的是IsARealNumber函数,当值是可表达的数字时返回true.
显然我可以写自己的......
public bool IsARealNumber(double test)
{
if (double.IsNaN(test)) return false;
if (double.IsInfinity(test)) return false;
return true;
}
Run Code Online (Sandbox Code Playgroud)
但似乎我不应该这样做.
项目是C#.
所以我有一堆多线程代码,旨在作为库运行.这是UI的一个单独项目.
我的库有一个中心对象,需要在创建触发事件的任何内容之前创建.
是否可以在某些对象中传递此主对象,以便我的事件可以确定何时需要调用它们以返回到主UI线程?
我真的很想让UI不必进行大量的调用,因为他的事件处理程序几乎总是从一些随机的后台线程调用.