小编Qwe*_*tie的帖子

替换WPF入口点

WPF定义了自己的Main()方法.我应该如何用我自己的Main方法替换它(通常)打开WPF MainWindow(例如通过命令行参数添加非WPF脚本模式)?

.net wpf entry-point

54
推荐指数
4
解决办法
3万
查看次数

WPF:如何使画布自动调整大小?

我希望我Canvas自动调整大小到其项目的大小,以便ScrollViewer滚动条具有正确的范围.这可以在XAML中完成吗?

<ScrollViewer HorizontalScrollBarVisibility="Auto" x:Name="_scrollViewer">
    <Grid x:Name ="_canvasGrid" Background="Yellow">
        <Canvas x:Name="_canvas" HorizontalAlignment="Left" VerticalAlignment="Top" Background="Green"></Canvas>
        <Line IsHitTestVisible="False" .../>
    </Grid>
</ScrollViewer>
Run Code Online (Sandbox Code Playgroud)

在上面的代码中,画布的大小始终为0,但它不会剪切其子元素.

.net wpf resize scrollviewer wpf-controls

43
推荐指数
5
解决办法
8万
查看次数

如果构造函数抛出异常,是否会调用析构函数?

寻找C#和C++的答案.(在C#中,用'finalizer'替换'析构函数')

c# c++ destructor finalizer

42
推荐指数
3
解决办法
1万
查看次数

.NET数组的开销?

我试图使用以下代码确定.NET数组(在32位进程中)标头的开销:

long bytes1 = GC.GetTotalMemory(false);
object[] array = new object[10000];
    for (int i = 0; i < 10000; i++)
        array[i] = new int[1];
long bytes2 = GC.GetTotalMemory(false);
array[0] = null; // ensure no garbage collection before this point

Console.WriteLine(bytes2 - bytes1);
// Calculate array overhead in bytes by subtracting the size of 
// the array elements (40000 for object[10000] and 4 for each 
// array), and dividing by the number of arrays (10001)
Console.WriteLine("Array overhead: {0:0.000}", 
                  ((double)(bytes2 - bytes1) - …
Run Code Online (Sandbox Code Playgroud)

.net c# arrays overhead

36
推荐指数
2
解决办法
7944
查看次数

WPF:如何绑定到嵌套属性?

我可以绑定到属性,但不能绑定到另一个属性中的属性.为什么不?例如

<Window DataContext="{Binding RelativeSource={RelativeSource Self}}"...>
...
    <!--Doesn't work-->
    <TextBox Text="{Binding Path=ParentProperty.ChildProperty,Mode=TwoWay}" 
             Width="30"/>
Run Code Online (Sandbox Code Playgroud)

(注意:我不是要做master-details或者其他任何东西.这两个属性都是标准的CLR属性.)

更新:问题是我的ParentProperty依赖于XAML中的一个对象被初始化.不幸的是,该对象后来在XAML文件中定义而不是Binding,因此当Binding读取ParentProperty时,该对象为null.由于重新排列XAML文件会搞砸布局,我能想到的唯一解决方案是在代码隐藏中定义Binding:

<TextBox x:Name="txt" Width="30"/>

// after calling InitializeComponent()
txt.SetBinding(TextBox.TextProperty, "ParentProperty.ChildProperty");
Run Code Online (Sandbox Code Playgroud)

wpf binding nested properties

35
推荐指数
2
解决办法
5万
查看次数

什么是StdAfx.h中的"Afx"?

我只是好奇Afx代表什么.那么FxCop中的Fx呢?

.net mfc fxcop stdafx.h

34
推荐指数
2
解决办法
8172
查看次数

标题栏中的标签:秘密是什么?

Chrome和Firefox 4以及其他应用程序现在将其部分用户界面放在标题栏中.在Windows中,操作系统通常控制整个标题栏.应用程序可以通过删除操作系统标题栏并绘制"假"标题栏(如WinAmp)来创建自定义标题栏,但只有操作系统知道如何绘制标题栏的非自定义元素(例如,关闭/最小化/ Maximize),因操作系统版本而异.

通过什么机制,Chrome和Firefox等应用程序与操作系统"共享"标题栏(在保留原始操作系统视觉主题的同时将自定义元素放在标题栏中)?

在此输入图像描述

在Chrome中,标签会侵占标题栏,因此标题文字空间不足.

windows user-interface titlebar custom-titlebar

31
推荐指数
2
解决办法
9037
查看次数

WPF:如何在StackPanel中进行控件拉伸?

放置在StackPanel中时,Slider和其他一些控件不会拉伸以填充可用空间; 相反,宽度始终为MinWidth(如果未设置MinWidth,则为大约10个像素).如何使其伸展(相当于WinForms中的Anchor.Left | Anchor.Right)?例:

<StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal">
    <Slider Value="14" SmallChange="0.5" Maximum="100" Minimum="4" 
            x:Name="FontSize" MinWidth="30" LargeChange="2" 
            TickFrequency="10" TickPlacement="TopLeft" 
            HorizontalAlignment="Stretch"/>
    <TextBlock Margin="8" Text="{Binding ElementName=FontSize, Path=Value}" 
               VerticalAlignment="Center"/>
</StackPanel>
Run Code Online (Sandbox Code Playgroud)

wpf slider stretch stackpanel

22
推荐指数
1
解决办法
2万
查看次数

为什么我不能在Release版本中将C++中的char*字符串返回给C#?

我试图从C#调用以下简单的C函数:

SIMPLEDLL_API const char* ReturnString()
{
    return "Returning a static string!";
}
Run Code Online (Sandbox Code Playgroud)

使用以下P/Invoke声明(使用或不使用return属性,它没有区别):

[DllImport("SimpleDll")]
[return: MarshalAs(UnmanagedType.LPStr)]
public static extern string ReturnString();
Run Code Online (Sandbox Code Playgroud)

如果DLL是Debug构建但在Release构建(AccessViolationException)中崩溃,则它可以工作.

我正在调用十几个其他简单的函数,这是唯一失败的函数(这里是其他函数:)

[DllImport("SimpleDll")] public static extern int NextInt();
[DllImport("SimpleDll")] public static extern void SetNextInt(int x);
[DllImport("SimpleDll")] public static extern int AddInts(int a, int b);
[DllImport("SimpleDll")] public static extern int AddFourInts(int a, int b, int c, int d);
[DllImport("SimpleDll")] public static extern double AddDoubles(double x, double y);
[DllImport("SimpleDll")] public static extern IntPtr AddDoublesIndirect(ref double x, ref double y);
[DllImport("SimpleDll")] [return: …
Run Code Online (Sandbox Code Playgroud)

.net pinvoke marshalling access-violation

20
推荐指数
2
解决办法
1万
查看次数

setVisibility(View.VISIBLE)并不总是有效.想法?

我试图显示一对隐藏的按钮(使用setVisibility(View.VISIBLE),在一个内RelativeLayout),但它并不总是有效.该按钮在Galaxy Tab 10.1上显示OK,但不在较小的平板电脑中(不确定是哪种型号),也不在Android 4.0仿真器上.

我随机发现,TextView t以下代码导致按钮变为可见:

t.setText(t.getText());
...
button.setVisibility(View.VISIBLE);
Run Code Online (Sandbox Code Playgroud)

t位于相同RelativeLayout但与按钮无关(它们的位置是独立且不重叠的).

编辑:如果某个Android开发人员想要追踪这个...

我能够将代码减少到以下布局,在Android 4.0.3仿真器上展示问题但不是Galaxy Tab.我发现我需要一个SurfaceView或者问题没有发生(例如,将其更改为TextView并且问题消失).

<?xml version="1.0" encoding="utf-8"?>
<!-- layout/test.xml -->
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"        
    android:id="@+id/relativeLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <SurfaceView
        android:id="@+id/mapCtrl"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_above="@+id/bottomPanel"
        android:text="Placeholder"
        android:layout_marginTop="18dip" />
    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:text="@string/map_mode_title" />

    <!--=================================================-->
    <!-- Bottom bar: current road name and current speed -->
    <LinearLayout
        android:id="@+id/bottomPanel"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="#f228"
        android:orientation="horizontal"
        android:textColor="#ffff" >
        <Button
            android:id="@+id/btnNavMode"
            android:layout_width="wrap_content" …
Run Code Online (Sandbox Code Playgroud)

android

19
推荐指数
3
解决办法
3万
查看次数