我的WPF应用程序生成的数据集可能每次都有不同的列数.输出中包含将用于应用格式的每列的说明.输出的简化版本可能类似于:
class Data
{
IList<ColumnDescription> ColumnDescriptions { get; set; }
string[][] Rows { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
此类在WPF DataGrid上设置为DataContext,但实际上我以编程方式创建列:
for (int i = 0; i < data.ColumnDescriptions.Count; i++)
{
dataGrid.Columns.Add(new DataGridTextColumn
{
Header = data.ColumnDescriptions[i].Name,
Binding = new Binding(string.Format("[{0}]", i))
});
}
Run Code Online (Sandbox Code Playgroud)
有没有办法用XAML文件中的数据绑定替换此代码?
我来到主题缓存和映射以及缓存未命中以及当所有块已满时缓存块如何以什么顺序替换.
有最近最少使用的算法或fifo算法或最不频繁的算法和随机替换,...
但是在实际的cpu缓存上使用了哪些算法?或者你可以使用所有...操作系统决定最佳算法是什么?
编辑:即使我选择了答案,欢迎任何进一步的信息;)
我想绘制实例多维数据集.
我可以GL.DrawArraysInstanced(PrimitiveType.Triangles, 0, 36, 2);成功打电话.
我的问题是所有的立方体都是在相同的位置和相同的旋转绘制的.我怎样才能为每个立方体单独更改?
要创建不同的位置等,我需要每个立方体的矩阵,对吧?我创造了这个:
Matrix4[] Matrices = new Matrix4[]{
Matrix4.Identity, //do nothing
Matrix4.Identity * Matrix4.CreateTranslation(1,0,0) //move a little bit
};
GL.BindBuffer(BufferTarget.ArrayBuffer, matrixBuffer);
GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(sizeof(float) * 16 * Matrices.Length), Matrices, BufferUsageHint.StaticDraw);
Run Code Online (Sandbox Code Playgroud)
这应该创建一个缓冲区,我可以存储我的矩阵.matrixBuffer是指向我的缓冲区的指针.我不确定大小是否正确,我采用浮动*4(对于Vector4)*4(对于4个向量)*数组大小.
绘制循环:
GL.BindBuffer(BufferTarget.ArrayBuffer, matrixBuffer);
GL.VertexAttribPointer(3, 4, VertexAttribPointerType.Float, false, 0, 0);
//GL.VertexAttribDivisor(3, ?);
GL.EnableVertexAttribArray(3);
GL.DrawArraysInstanced(PrimitiveType.Triangles, 0, 36, 2);
Run Code Online (Sandbox Code Playgroud)
任何高于4的数字VertexAttribPointer(..., 4, VertexattribPointerType.Float, ...);都会导致崩溃.我认为我必须将该值设置为16?
我不确定我是否需要一个VertexAttribDivisor,可能我需要这个每36个顶点所以我打电话GL.VertexAttribDivisor(3, 36);?但是当我这样做时,我看不到任何立方体.
我的顶点着色器:
#version 330 core
layout(location = 0) in vec3 position;
layout(location = 1) in vec4 color; …Run Code Online (Sandbox Code Playgroud) 我想更改AvalonDock的Metro主题颜色.我还询问了有关Codeplex的相关问题,但到目前为止我还没有得到答案.
我将以下XAML(源文件)识别为我想要更改的颜色:
<Style TargetType="avalonDockControls:AnchorablePaneTitle">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
...
<ControlTemplate.Triggers>
...
<DataTrigger Binding="{Binding Model.IsActive, RelativeSource={RelativeSource Mode=Self}}" Value="True">
<!-- following XAML line -->
<Setter Property="BorderBrush" Value="{DynamicResource AvalonDock_ThemeMetro_BaseColor3}" />
<Setter Property="BorderThickness" Value="0,3,0,0"/>
</DataTrigger>
...
</ControlTemplate.Triggers>
...
Run Code Online (Sandbox Code Playgroud)
你可以看到:画笔获得了BaseColor3(默认为蓝色).
现在我改变了我的XAML中的颜色:
<Window.Resources>
...
<SolidColorBrush x:Key="AvalonDock_ThemeMetroBaseColor3" Color="Red" />
</Window.Resources>
Run Code Online (Sandbox Code Playgroud)
没有什么变化.颜色保持蓝色.现在我很困惑.所以它必须是错误的属性来改变或某些东西阻止颜色改变或/和内部它使用旧值或东西......
为什么不起作用?我怎样才能发现这些问题并修复它?
我有一个这样的课:
class ContentManager : IDisposable
{
List<int> idlist = new List<int>();
public int Load(string path)
{
//Load file, give content, gets an id
//...
int id = LoadFile(myfilecontent);
idlist.Add(id);
return id;
}
public void Dispose()
{
//Delete the given content by id, stored in idlist
foreach(int id in idlist)
{
DeleteContent(id);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我想让它成为静态的,因为我只需要一个实例,并且可以在不提供实例的情况下从其他所有类访问该函数.
我可以使其中的每个变量都是静态的,函数是静态的.
但我的问题是这个IDisposable.我不能在静态类中使用接口.我怎么能在最后做一些动作?我的意思是我可以删除该接口,但将函数保留在其中并使用我的主类,当我的主类被释放时,我调用ContentManager.Dispose().但是当我忘记在我的主...
你有一个很好的解决方案吗?确保每次程序关闭时都调用Dispose?
编辑:我在图形卡中加载数据并返回指针.当我的应用程序关闭时,我需要从显卡中删除内容.为了安全起见,一切都被删除了,我使用了dispose.
我目前正在尝试使用着色器构建一个测试场景。这是我的代码。
vertexArray = GL.GenVertexArray();
GL.BindVertexArray(vertexArray);
float[] Vertices = new float[] {
-1.0f, -1.0f, 0.0f,
1.0f, -1.0f, 0.0f,
0.0f, 1.0f, 0.0f,
};
float[] Colors = new float[] {
1.0f, 1.0f, 0.0f, 1.0f,
1.0f, 1.0f, 0.0f, 1.0f,
0.0f, 1.0f, 0.0f, 1.0f
};
vertexBuffer = GL.GenBuffer();
colorBuffer = GL.GenBuffer();
GL.BindBuffer(BufferTarget.ArrayBuffer, vertexBuffer);
GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(sizeof(float) * Vertices.Length), Vertices, BufferUsageHint.StaticDraw);
GL.BindBuffer(BufferTarget.ArrayBuffer, colorBuffer);
GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(sizeof(float) * Colors.Length), Colors, BufferUsageHint.StaticDraw);
//Loading shaders...
Run Code Online (Sandbox Code Playgroud)
我的渲染循环:
GL.UseProgram(shaderProgram);
GL.EnableVertexAttribArray(0);
GL.BindBuffer(BufferTarget.ArrayBuffer, vertexBuffer);
GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, 0, 0);
GL.BindBuffer(BufferTarget.ArrayBuffer, colorBuffer);
GL.VertexAttribPointer(1, 3, VertexAttribPointerType.Float, …Run Code Online (Sandbox Code Playgroud) 我有一个类,其属性绑定到我的视图.为了使我的视图保持最新,我实现了INotifyPropertyChanged并在每次某些属性更改时引发事件.
现在我得到了一些重要的函数来冻结我的应用程序 我想把它们放到后台任务中.
第一:这是我目前的做法
(例如点击按钮)
private async void HeavyFunc()
{
foreach (var stuff)
{
count += await Task.Run(() => stuff.Fetch());
}
if (count == 0)
//...
}
Run Code Online (Sandbox Code Playgroud)
东西类
public async Task<int> Fetch()
{
//network stuff
RaisePropertyChanged("MyProperty");
}
public async void RaisePropertyChanged(string pChangedProperty)
{
await Application.Current.Dispatcher.BeginInvoke(
System.Windows.Threading.DispatcherPriority.Normal,
new ThreadStart(() =>
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(pChangedProperty);
}
);
}
Run Code Online (Sandbox Code Playgroud)
上面的代码给出了一个异常("DependencySource"必须在同一个线程中创建,如"DependencyObject").
AFAIK,你通常需要创建一个新线程并运行它(等待它).'goit Task.Run(...);'应该做这个工作.
由于PropertyChanged事件直接影响UI,因此在UI线程中调用它似乎是一个很好的决定.这就是我调用Dispatcher.BeginInvoke的原因.
我不明白:上面的例外是由不同的线程负责数据引起的.但我明确地在我的UI线程上调用该事件,该对象也应该由UI线程创建.那么为什么我会得到例外?
我的主要问题是:如何实现INotifyPropertyChanged接口的事件通常是为了避免或处理上面的大多数异步编程问题?构建函数时应该考虑什么?