2014-11-03 4 views
1

Silverlight 응용 프로그램이 있습니다.ElementName 바인딩 도구 설명

나는 작동하지 않는가 elementName과 기타 요소 (A의 GridView)

<ToolTipService.ToolTip> 
    <ToolTip> 
     <TextBlock x:Name="Test" 
      VerticalAlignment="Center" 
      FontSize="12" 
      Margin="10,0,0,0" 
      Foreground="DimGray" 
      Visibility="Visible"> 
      <Run Text="{Binding Path=Items.Count, 
       ElementName=SearchResultsPresenter, 
       StringFormat=\{0:N0\}}"/> 
      <Run Text="{Binding 
       Source={StaticResource PublicResourceStrings}, 
       Path=ResourceStrings.SEARCH_RESULTS_DISPLAYED}"/> 
      <Run Text="{Binding SelectedItems.Count, 
       ElementName=SearchResultsPresenter, 
       StringFormat=\{0:N0\}}"/> 
      <Run Text="{Binding 
       Source={StaticResource PublicResourceStrings}, 
       Path=ResourceStrings.SEARCH_RESULTS_SELECTED}"/> 
     </TextBlock> 
    </ToolTip> 
</ToolTipService.ToolTip> 

그러나 바인딩에 대한 정보를 표시하는 TextBlock의에 툴팁을 추가해야합니다. Items.Count 및 SelectedItems.Count 표시 "0"...

나는 this을 찾았지만 조금 복잡해 보입니다. 필요한 것을하기위한 간단한 해결책이 있습니까?

+0

는 HTTP 당신의 GridView입니다 : //www.red-gate.com/products/dotnet-development/ants-memory-profiler/learning-memory-management/WPF-silverlight-pitfalls)) 당신은 gridview를 채우는 바인딩 경로에 바인딩하고 싶습니다. 당신의 카운트를 얻기 위해서. 더 많은 코드를 공유 할 수 있습니다. –

+0

Thx. 예, SearchResultsPresenter는 ItemsSource = "{Binding SearchResults}"속성을 사용하는 My GridView (실제로 RadGridView ... Telerik에서 제공)입니다. 내 ToolTip에 Items.Count 대신이 바인딩을 사용할 수 있지만 어떻게 SelectedItems.Count를 표시 할 수 있습니까? – Gab

답변

2
<Grid> 
    <Grid.Resources> 
     <BindableObjectReference x:Key="BindableGridView" 
      Object="{Binding ElementName=SearchResultsPresenter}"/> 
    </Grid.Resources> 
    <RadGridView x:Name="SearchResultsPresenter" 
     ItemsSource="{Binding SearchResults}"> 
     <ToolTipService.ToolTip> 
      <ToolTip> 
       <TextBlock> 
       <Run Text="{Binding 
        Path=Object.Items.Count, 
        Source={StaticResource BindableGridView}}"/> 
       <Run Text="{Binding 
        Path=Object.SelectedItems.Count, 
        Source={StaticResource BindableGridView}}"/> 
       </TextBlock> 
      <ToolTip> 
     <ToolTipService.ToolTip> 
    </RadGridView> 
</Grid> 

코드 : (그것은 당신이 (Children.Count을 할 거라고 생각하면있는 거의 GridView이다하지만이 [메모리 누수] 야기 만약 내가 SearchResultsPresenter 가정

public class BindableObjectReference : DependencyObject 
{ 
    public object Object 
    { 
     get { return GetValue(ObjectProperty); } 
     set { SetValue(ObjectProperty, value); } 
    } 

    public static readonly DependencyProperty ObjectProperty = 
     DependencyProperty.Register("Object", typeof(object), 
     typeof(BindableObjectReference), new PropertyMetadata(null)); 
} 
+0

너는 너에게 너무 쉽게 사람들에게 너를 그것에게 만든다 –

+0

나는 그것을 도울 수 없다. 나는 Silverlight 괴상한이야;) – Martin

+0

그건 너무 자주 요즘 듣지 않는 문구이지만, 나도 그래. –