C#功能在我的XAML我有這樣調用從XAML
<Expander ExpandDirection="Down" Width="Auto" Padding="4">
<Expander.Style>
<Style TargetType="Expander">
<Setter Property="IsExpanded" Value="{Binding [email protected]}" />
<Setter Property="Header" Value="{Binding [email protected]}" />
<Setter Property="FontWeight" Value="Bold" />
<Style.Triggers>
<DataTrigger Binding="{Binding IsExpanded,RelativeSource={RelativeSource Self}}" Value="True">
</DataTrigger>
</Style.Triggers>
</Style>
</Expander.Style>
<ListBox Name="itemsList"
ItemsSource="{Binding XPath=UpgradeAction}"
ItemTemplate="{StaticResource dtListItemTemplate}"
SelectionChanged="listItems_SelectionChanged"
Style="{StaticResource styleListBoxUpgradeAction}"
ItemContainerStyle="{StaticResource styleListBoxItemUpgradeAction}">
</ListBox>
</Expander>
而是頭的值的擴張來自@Name我想有一個C#函數採取在@Name從XAML,做一些事情,然後輸出一個新的字符串作爲Value。因此,這將是這個樣子
<Setter Property="Header" Value="C_Sharp_Function({Binding [email protected]})" />
我有我需要使用,但我怎麼在XAML執行呢?很抱歉,如果這聽起來像一個愚蠢的問題的功能,我是新來的C#和XAML 。任何幫助深表感謝!
編輯
下面是一些我在二傳手試圖替換一個多值轉換的東西。我認爲它應該看起來像this中的答案。
<Setter Property="Header" Value="{{Binding [email protected], Converter={StaticResource NameConverter}}, {Binding [email protected], Converter={StaticResource NameConverter}}}" />
<Setter Property="Header" Value="{Binding XPath={@Name, @Value}, Converter={StaticResource NameConverter}}" />
綁定到你的視圖模型的屬性,並在吸氣的屬性把代碼你的功能 – Milney
我有點認同@Milney,爲什麼不直接在你的viewmodel上使用返回Header的正確值的屬性呢?爲什麼需要這樣做呢? –
但這是轉換器所做的。因此,添加一個轉換器到你的綁定,並做你需要的。 – Evk