Есть много способов сделать sh это. Один из способов - реализовать пользовательский конвертер.
[ValueConversion(typeof(string), typeof(bool))]
public class UsernameToEnabledConverter : IValueConverter {
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
var username = value.ToString();
// The GetCurrentUserName() method is your way to get the current logged user name.
if (username == GetCurrentUserName()) {
return true;
}
return false;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
throw new NotSupportedException();
}
}
Затем вы связываете свойство Button.IsEnabled со свойством Username и используете конвертер (я поместил только важный код):
<Window
...
<Window.Resources>
<local:UsernameToEnabledConverter x:Key="UsernameToEnabledConverter" />
</Window.Resources>
<Grid>
<DataGrid
...
ItemsSource="{Binding}">
<DataGrid.Columns>
...
<DataGridTextColumn Binding="{Binding Path=Username}" Header="Username" />
...
<DataGridTemplateColumn Header="Update">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate x:Name="Button_Update_Temp" DataType="local:CustomVm">
<Button
x:Name="btnUpdate"
Click="btnUpdate_Click" Content="Update"
IsEnabled="{Binding Username, Converter={StaticResource UsernameToEnabledConverter}}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
</Grid>
</Window>