美文网首页
DataTemplate Binding ContentCont

DataTemplate Binding ContentCont

作者: bettyxue | 来源:发表于2020-07-24 10:59 被阅读0次

使用场景:

N个气体成分组成一个100%的气体组分。对于设置每一个气体成份的时候我们都会去触发一个事件自动计算所有气体组分的和

GridView列出所有的气体组分

<ListView ItemsSource="{Binding GasCompositionList}" Background="Transparent">

                <ListView.View>

                    <GridView>

                        <GridViewColumn Header="Gas Name" CellTemplate="{StaticResource GasNameDT}"/>

                        <GridViewColumn Header="Symbol" CellTemplate="{StaticResource GasSymbolDT}"/>

                        <GridViewColumn Header="Mole %" CellTemplate="{StaticResource MoleDT}" />

                    </GridView>

                </ListView.View>

            </ListView>

下面是对应的DataTemplate

<DataTemplate x:Key="GasNameDT">

            <TextBlock Text="{Binding GasName}" HorizontalAlignment="Left" VerticalAlignment="Center" Width="150"/>

        </DataTemplate>

        <DataTemplate x:Key="GasSymbolDT">

            <TextBlock Text="{Binding Symbol}" HorizontalAlignment="Center" VerticalAlignment="Center" Width="60"/>

        </DataTemplate>

        <DataTemplate x:Key="MoleDT">

            <TextBox Height="17" Width="60" Text="{Binding Mole,UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Center" VerticalAlignment='Center'>

                <i:Interaction.Triggers>

                    <i:EventTrigger EventName="TextChanged">

                        <i:InvokeCommandAction Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.CalcuFreeGasCompositionCommand}"/>

                    </i:EventTrigger>

                </i:Interaction.Triggers>

            </TextBox>

        </DataTemplate>

相关文章

网友评论

      本文标题:DataTemplate Binding ContentCont

      本文链接:https://www.haomeiwen.com/subject/xlcjlktx.html