Ich versuche Tooltip zu Zelle Wert bei DevExpress Grid Control zur Bindung, aber i "verloren" Datacontext bei Setter.Value Eigenschaft:So finden Sie DataContext in der Setter Value-Eigenschaft?
Hier wird der vollständige Code von Gridcontrol (nur eine Spalte):
<dxg:GridControl Grid.Row="0"
x:Name="grid"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
dx:ThemeManager.ThemeName="Seven"
ScrollViewer.CanContentScroll="True"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
ScrollViewer.VerticalScrollBarVisibility="Auto"
ItemsSource="{Binding ObjectViewModel.Collection,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
SelectedItem="{Binding CurrentElement,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged,TargetNullValue=null}"
>
<dxg:GridControl.View>
<!--region #RowCellMenuCustomization-->
<dxg:TableView x:Name="view" AutoWidth="True"
UseLightweightTemplates="None"
>
</dxg:TableView.RowCellMenuCustomizations>
</dxg:TableView>
<!--endregion #RowCellMenuCustomization-->
</dxg:GridControl.View>
<dxg:GridControl.Columns>
<dxg:GridColumn
Header="Address"
Binding="{Binding Address,Mode=OneWay,UpdateSourceTrigger=PropertyChanged}"
AllowEditing="False"
HorizontalHeaderContentAlignment="Stretch"
Width="*"
AllowResizing="True"
HeaderToolTip="Address"
>
<dxg:GridColumn.CellStyle
>
<Style x:Name="toolTipStyle"
BasedOn="{StaticResource {dxgt:GridRowThemeKey ResourceKey=CellStyle}}"
TargetType="dxg:GridCellContentPresenter">
<Setter Property="ToolTip">
<Setter.Value>
<TextBlock Text="{Binding Path=Address,RelativeSource={RelativeSource Self},Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"/>
</Setter.Value>
</Setter>
</Style>
</dxg:GridColumn.CellStyle>
</dxg:GridColumn>
</dxg:GridControl.Columns>
</dxg:GridControl>
Collection-Klasse Code:
public class Element
{
public String Address
{
returm SomeObject.Address;
}
//other properties
}
So dank this answer: es funktioniert für einige nicht verbindlichen Text, aber wenn ich versuche, es zu Eigenschaft Bindung funktioniert es nicht.
Visual Studio Ausgabefenster Protokoll:
System.Windows.Data Error: 40 : BindingExpression path error: 'Address' property not found on 'object' ''TextBlock' (Name='')'. BindingExpression:Path=Address; DataItem='TextBlock' (Name=''); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')
Es scheint, dass ich Datacontext verloren, aber wie es bei Setter.Value zu binden?
P.S. @ Rekshino, ich dies tun und Ausgabeprotokoll ist:
System.Windows.Data Error: 40 : BindingExpression path error: 'Address' property not found on 'object' ''EditGridCellData' (HashCode=41748728)'. BindingExpression:Path=DataContext.Address; DataItem='TextBlock' (Name=''); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')
Es ist richtig, dass es nicht funktioniert. Ich habe nicht gewusst, dass devExpress einen Wrapper benutzt. Die Antwort von mm8 sollte also korrekt sein, siehe auch: https://stackoverflow.com/questions/34687716/wpf-binding-errors – Rekshino