Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何将fontsize从combobox绑定到datagrid_C#_Wpf_Data Binding_Combobox_Datagrid - Fatal编程技术网

C# 如何将fontsize从combobox绑定到datagrid

C# 如何将fontsize从combobox绑定到datagrid,c#,wpf,data-binding,combobox,datagrid,C#,Wpf,Data Binding,Combobox,Datagrid,如何使用fontsize将值从combobox绑定到datagrid?我试过了,但没用 <ComboBox Name="FontSizeComboBox" IsEditable="True" Width="60" SelectedIndex="1" Foreground="White"> <ComboBox.ItemsSource> <x:Array T

如何使用fontsize将值从combobox绑定到datagrid?我试过了,但没用

  <ComboBox Name="FontSizeComboBox" IsEditable="True" 
        Width="60" SelectedIndex="1"
                  Foreground="White">
            <ComboBox.ItemsSource>
                <x:Array Type="{x:Type System:Int32}">
                    <System:Int32>12</System:Int32>
                    <System:Int32>14</System:Int32>
                    <System:Int32>16</System:Int32>
                    <System:Int32>18</System:Int32>
                    <System:Int32>20</System:Int32>
                    <System:Int32>22</System:Int32>
                    <System:Int32>24</System:Int32>
                    <System:Int32>26</System:Int32>
                    <System:Int32>28</System:Int32>
                </x:Array>
            </ComboBox.ItemsSource>
        </ComboBox>
   <DataGrid Grid.Row="1" x:Name="dgrPoints" ItemsSource="{Binding Stations}" VerticalAlignment="Top" AutoGenerateColumns="False" CanUserResizeColumns="True"
              FontSize="{Binding  Path=SelectedIndex.Value ,ElementName=FontSizeComboBox}" CellEditEnding="dgrPoints_CellEditEnding">

12
14
16
18
20
22
24
26
28
SelectedIndex
顾名思义是一个整数。它没有
属性。这是用户选择的项目的索引。如果用户选择第四项,它将是整数值
3

通常,我会这样说:

FontSize="{Binding SelectedValue, ElementName=FontSizeComboBox}"
…但是您的
组合框
ias
IsEditable=“True”
,因此您希望使用
文本
SelectedValue
只能包含列表中的值,但是
Text
可以是用户键入的任何内容

另外,如果要绑定到
SelectedValue
,还需要将字体大小项目类型更改为
double
,因为
FontSize
属性上的绑定可以自动从字符串转换,但不能从
Int32
(当然,
ComboBox.Text
是字符串):


12
14
16
18
20
22
24
26
28

谢谢!它起作用了!如果我正在通过组合框中的剪贴板更改大小,如何使用datagrid进行绑定?@DonKiHot先生,我的错。更新了我的答案。
FontSize="{Binding SelectedValue, ElementName=FontSizeComboBox}"
<ComboBox.ItemsSource>
    <x:Array Type="{x:Type System:Double}">
        <System:Double>12</System:Double>
        <System:Double>14</System:Double>
        <System:Double>16</System:Double>
        <System:Double>18</System:Double>
        <System:Double>20</System:Double>
        <System:Double>22</System:Double>
        <System:Double>24</System:Double>
        <System:Double>26</System:Double>
        <System:Double>28</System:Double>
    </x:Array>
</ComboBox.ItemsSource>