小编Ωme*_*Man的帖子

ListBoxItem Horizo​​ntalContentAlignment在ListBox的整个宽度上拉伸

ListBoxItem在Windows Phone 8应用程序上遇到问题,同时试图让它们伸展到所有宽度ListBox.

我的ListBox:

<ListBox 
      ItemsSource="{Binding Events}" 
      behaviors:ItemClickCommandBehavior.Command="{Binding EventSelectedCommand}"
      ItemTemplate="{StaticResource EventListTemplateSelector}"/>
Run Code Online (Sandbox Code Playgroud)

它的DataTemplates在一个单独的xaml资源文件中:

<DataTemplate x:Key="EventListHeaderTemplate">
    <Border HorizontalAlignment="Stretch">
        <Grid Height="50">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="6*"/>
            </Grid.ColumnDefinitions>
            <Image Grid.Column="0" Source="{Binding ImageUri}" VerticalAlignment="Center" HorizontalAlignment="Center" Height="30"/>
            <TextBlock Grid.Column="1" Text="{Binding SomeText}" VerticalAlignment="Center" HorizontalAlignment="Left" Foreground="Black"/>
        </Grid>
    </Border>
</DataTemplate>
Run Code Online (Sandbox Code Playgroud)

我不能让这些物品真正拉伸,我不知道问题出在哪里.我试图设置ItemContainerStyleHorizo​​ntalCOntentAlignment ="Stretch",但它不起作用.我已经尝试了许多其他组合,似乎只将Border或Grid宽度设置为常量工作,另一个有效的解决方案是将Border宽度设置为绑定到包含ListBox的ActualWidth,但我想使用Stretch变种如果可以使它工作.

xaml listbox alignment listboxitem windows-phone-8

9
推荐指数
1
解决办法
2660
查看次数

PDFsharp自动换行

我似乎无法理解如何使用PDFsharp在我创建的矩形中包装文本.我已经看过文章解释如何,但是当我尝试它时,我的文本仍然延伸到PDF的页面.任何帮助都会很棒(这是我第一次使用PDFsharp).

rect = new XRect(20, 300, 400, 100);
tf.Alignment = XParagraphAlignment.Left;
gfx.DrawString("\t • Please call the borrower prior to closing and confirm your arrival time and the closing location. \n", font, XBrushes.Black, rect, XStringFormats.TopLeft);
rect = new XRect(20, 320, 100, 100);
gfx.DrawString("\t • If the borrower needs to change the closing appointment time or date for any reason please have them call McDonnell Law Firm at 866-931-8793 \n", font, XBrushes.Black, rect, XStringFormats.TopLeft);
rect = new XRect(20, 340, 100, 100);
gfx.DrawString("\t …
Run Code Online (Sandbox Code Playgroud)

c# pdfsharp

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

带有Robocopy的Powershell(或#$(*&我如何传递参数对吗?)

我正在尝试编写一个使用robocopy的脚本.如果我只是手动执行此操作,我的命令将是:

robocopy c:\ hold\test1 c:\ hold\test2 test.txt/NJH/NJS

但是,当我从powershell执行此操作时,例如:

robocopy c:\hold\test1 c:\hold\test2 test.txt /NJH /NJS
Run Code Online (Sandbox Code Playgroud)

我明白了:

$source = "C:\hold\first test"
$destination = "C:\hold\second test"
$robocopyOptions = " /NJH /NJS "
$fileList = "test.txt"

robocopy $source $destination $fileLIst $robocopyOptions
Run Code Online (Sandbox Code Playgroud)

但是,如果我将robocopy命令更改为

-------------------------------------------------------------------------------
   ROBOCOPY     ::     Robust File Copy for Windows
-------------------------------------------------------------------------------

  Started : Fri Apr 10 09:20:03 2015

   Source - C:\hold\first test\
     Dest - C:\hold\second test\

    Files : test.txt

  Options : /COPY:DAT /R:1000000 /W:30

------------------------------------------------------------------------------

ERROR : Invalid Parameter #4 : " /NJH /NJS …
Run Code Online (Sandbox Code Playgroud)

powershell robocopy command-line-arguments

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

当设置标题的MaxWidth时,为所有DataGridColumns应用相同的高度

我有一个ItemsControl包含动态可变数量的DataGrids:

<ItemsControl ItemsSource="{Binding Table.Columns}">
   <ItemsControl.ItemsPanel>
      <ItemsPanelTemplate>
         <StackPanel Orientation="Horizontal" VerticalAlignment="Stretch"/>
      </ItemsPanelTemplate>
   </ItemsControl.ItemsPanel>

   <ItemsControl.ItemTemplateSelector>
      <local:ColumnTemplateSelector InputParameterColumnTemplate="{StaticResource InputParamterColumn}"
                                    SingleParameterColumnTemplate="{StaticResource SingleParameterColumn}"/>
   </ItemsControl.ItemTemplateSelector>
</ItemsControl>
Run Code Online (Sandbox Code Playgroud)

"SingleParameterColumn"的模板定义如下:

    <DataTemplate x:Key="SingleParameterColumn">       
        <DataGrid AutoGenerateColumns="False" ItemsSource="{Binding Cells}"      
                                   RowHeight="25" RowHeaderWidth="0" >
            <DataGrid.Columns>
                <DataGridTemplateColumn>
                    <DataGridTemplateColumn.HeaderTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Text="{Binding Name}"
                                           TextWrapping="Wrap"
                                           TextAlignment="Center"
                                           MaxWidth="60">
                                </TextBlock>
                                <Button>
                                    <Image ... />
                                </Button>
                            </StackPanel>
                        </DataTemplate>
                    </DataGridTemplateColumn.HeaderTemplate>
                    <DataGridTemplateColumn.CellTemplateSelector>....
                    </DataGridTemplateColumn.CellTemplateSelector>
                </DataGridTemplateColumn>
            </DataGrid.Columns>
        </DataGrid>
    </DataTemplate>
Run Code Online (Sandbox Code Playgroud)

总有一个InputParameterColumn,至少有一个SingleParameterColumn.它InputParameterColumn具有固定的标题名称,而标题SingleParameterColumn可以任意长.

因为我不希望有很宽列我已经定义了MaxWidthTextBlock在头模板60,这将导致头要高,如果一列的名称很长.

这会导致列具有不同的高度,具体取决于标题名称的长度. 这是问题:

有什么方法可以找出我的ItemsControl中最高的标题有多高,然后为所有其他标题设置相同的高度,以便我的列都具有相同的大小?

c# wpf xaml

9
推荐指数
1
解决办法
562
查看次数

在XAML中,我想使用StringFormat来显示数值,而不会发生任何舍入.可能吗?

所以在我的XAML中我有这个:

<TextBlock Text="{Binding MyDecimalProperty, StringFormat={}{0:#.###}}"/>
Run Code Online (Sandbox Code Playgroud)

当MyDecimalProperty的值是例如5.35570256时,显示的TextBlock值是5.356

有没有办法让TextBlock显示5.355(即截断数字而不是舍入它)使用StringFormat?

我知道我可以使用值转换器,但我想知道我是否可以使用StringFormat或XAML中定义的任何其他内容来实现相同的功能.

更新:人们一直在想我为什么不想使用转换器.请以粗体显示.这不是我不想要的; 我只是想知道我是否可以使用StringFormat或任何其他XAML构造做同样的事情.

谢谢.

c# wpf xaml string-formatting

9
推荐指数
1
解决办法
5374
查看次数

ListBox SelectedItems绑定

我想将Listbox selectedItems绑定到数组.但.NET在运行时抛出异常.

d.SetBinding(ListBox.SelectedItemsProperty, new Binding { Source = SomeArray });
Run Code Online (Sandbox Code Playgroud)

dXAML中的一些ListBox 在哪里.

例外:

所选项目无法绑定.

为什么?

c# data-binding wpf

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

如何在Visual Studio中更改控制台应用程序的图标?

我正在使用VS 2008中的C#Console App,我无法更改图标文件.

我在项目 - >属性 - >应用程序选项卡中更改了图标文件,但仍然显示旧图标与新构建.

从帖子中检查以下答案以修改.resx文件.但我的应用程序只有一个.cs文件,而.resx文件是空的.

Visual Studio,更改应用程序图标,如何?

任何帮助是极大的赞赏.

c# icons console-application visual-studio

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

获得数字的因素

问题:我正在尝试重构此算法以使其更快.什么是速度的第一次重构?

public int GetHowManyFactors(int numberToCheck)
    {
        // we know 1 is a factor and the numberToCheck
        int factorCount = 2; 
        // start from 2 as we know 1 is a factor, and less than as numberToCheck is a factor
        for (int i = 2; i < numberToCheck; i++) 
        {
            if (numberToCheck % i == 0)
                factorCount++;
        }
        return factorCount;
    }
Run Code Online (Sandbox Code Playgroud)

c# math performance factors

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

错误无法访问本地服务器场.具有FeatureDependencyId的Cmdlet未注册

我试图从Windows批处理文件运行PowerShell脚本.这是一个使用的SharePoint相关脚本Import-SPData.

使用USERA登录时,这没有任何问题.但是,如果我尝试从USERB登录运行相同的批处理文件,我会收到以下错误:

c:\PS>ExecMyPowershellScript.bat

c:\PS>C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -psconsolefile "
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\CONFIG\P
OWERSHELL\Registration\psconsole.psc1" -command "c:\ps\MyPSScript.ps1"
Run Code Online (Sandbox Code Playgroud)

当地农场无法抵达.具有FeatureDependencyId的Cmdlet未注册.

Import-SPData:无法访问本地服务器场.验证本地服务器场是否已正确配置,当前是否可用,以及您是否具有访问数据库的相应权限,然后再次尝试.

At C:\ps\Run_MyPSScript.ps1:5 char:18
Run Code Online (Sandbox Code Playgroud)

USERB有权运行batps1文件.

sharepoint batch-file powershell-2.0 sharepoint-2010

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

无法加载类型 Microsoft.Azure.WebJobs.ParameterBindingData

我目前正在 VS Code 中开发 Azure 函数。我遇到了一个错误,该错误已在此 GitHub问题中报告。错误全文如下:Microsoft.Azure.WebJobs.Extensions.ServiceBus: Could not load type 'Microsoft.Azure.WebJobs.ParameterBindingData' from assembly 'Microsoft.Azure.WebJobs, Version=3.0.34.0, Culture=neutral, PublicKeyToken=****'. Value cannot be null. (Parameter 'provider')

建议的解决方案之一是降级Microsoft.Azure.WebJobs.Extensions.Storage. 但是,我不知道如何从扩展包降级包。在我的本地开发环境中,我使用以下默认host.json配置:

{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    }
  },
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[3.15.0, 4.0.0)"
  }
}
Run Code Online (Sandbox Code Playgroud)

我已经尝试了多个版本范围,每个版本范围都会导致相同的错误。由于我不熟悉.NET,因此我希望获得有关如何降级软件包以解决此问题的任何帮助或建议。谢谢。

附加信息: 我正在使用测试触发器在本地开发 EventHub 触发函数:

@app.function_name(name="EventHubTrigger1")
@app.event_hub_message_trigger(arg_name="myhub", event_hub_name="samples-workitems",
                               connection="") 

def test_function(myhub: func.EventHubEvent):
    logging.info('Python EventHub trigger processed an event: %s',
                myhub.get_body().decode('utf-8')) …
Run Code Online (Sandbox Code Playgroud)

azure azure-functions azure-functions-core-tools

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