2017-05-08 11 views
0

コンボボックスからDataGridにfontsizeで値をバインドする方法はありますか?私はそれを試してみましたが、それはその名の通り、整数であるコンボボックスからデータグリッドにfontsizeをバインドする方法

<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"> 

答えて

0
FontSize="{Binding Text, ElementName=FontSizeComboBox}" 

SelectedIndex仕事didntの。 Valueプロパティはありません。これは、ユーザーが選択する項目のインデックスです。ユーザーが4番目の項目を選択した場合、整数値は3になります。

通常、私はこれを言うと思います:

FontSize="{Binding SelectedValue, ElementName=FontSizeComboBox}" 

...しかし、あなたのComboBox IAS IsEditable="True"を、あなたの代わりにTextをしたいので。 、SelectedValueはリストのみで見つかった値を持つことができますが、TextはあなたがSelectedValueに結合された場合。

で、ユーザーのタイプはまた、あなたもdoubleにあなたのフォントサイズの項目タイプを変更する必要があると思い何もすることができます自動的に文字列からではなく、Int32から変換することができますFontSizeプロパティに結合するので(とComboBox.Textすることはもちろん、文字列です):

<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> 
+0

はありがとうございました!それは働いている!そして、もし私がコンボボックスでクリップボードでサイズを変更したら、それをDataGridにバインドするのですか? –

+0

@ Mr.DonKiHotおっと、私の悪い。私の答えを更新しました。 –

関連する問題