BarButtonItem

Jul 28, 2014 at 1:20 PM
Hi Peter,

I have a little issue with Caliburn.Micro.FrameworkContentElement. It works like charm when I use it with BarButtonItem inside Barmanager. But inside TableView.RowCellMenuCustomizations i get exception:

{"'DevExpress.Xpf.Bars.BarButtonItem' is not a Visual or Visual3D."}

Here is code using DXGrid:
<views:MyGrid
    x:Name ="ForViews"
    Grid.Row="3"
    ColumnGeneratorTemplate="{StaticResource DefaultColumnTemplate}"
    ColumnsSource="{Binding Columns}"
    AutoGenerateColumns="None"
    CurrentItem="{Binding SelectedRow}"
    VisibleRowCount2="{Binding VisibleRowCount, Mode=TwoWay}">
            <dxg:GridControl.View>
                <dxg:TableView Name="TableView1"
                       NavigationStyle="Row"
                       AutoWidth="False"
                       AllowEditing="False"
                       AlternateRowBackground="{StaticResource EvenRowBrush}"
                       AlternationCount="2">
                    <dxg:TableView.RowCellMenuCustomizations>
                        <dxb:BarButtonItem x:Name="BarButtonItem1" 
                                   Content="Do Something"
                                   frameworkContentElement:Message.Attach="[Event ItemClick] = [Action OpenCommand()]"
                                   >
 
                        </dxb:BarButtonItem>
                    </dxg:TableView.RowCellMenuCustomizations>
                </dxg:TableView>
            </dxg:GridControl.View>
        </views:MyGrid>
MyGrid is just inherit from GridControl
public class MyGrid : GridControl
{
    public int VisibleRowCount2
    {
        get { return (int)GetValue(VisibleRowCount2Property); }
        set { SetValue(VisibleRowCount2Property, value); }
    }
    public static readonly DependencyProperty VisibleRowCount2Property =
        DependencyProperty.Register("VisibleRowCount2", typeof(int), typeof(MyGrid),
        new PropertyMetadata(0));
    public MyGrid()
    {
        LayoutUpdated += MyGrid_LayoutUpdated;
    }
    void MyGrid_LayoutUpdated(object sender, EventArgs e)
    {
        VisibleRowCount2 = VisibleRowCount;
    }
}
I have no clue what to do. Could you look at it and helps me please?

Thank you
David
Aug 22, 2014 at 4:18 PM
Hi David,

I'm sorry for the late response, but I was on a holiday with my family, so I didn't read the email notifications.
I've never tried using it inside a Grid, so I have no idea about what's wrong, but I will take a look at it next week.

Regards,
Peter
Aug 22, 2014 at 7:41 PM

Hi Peter,

I already solved it. There is problem with binding, because in the control is another datacontext, but once you put this line:

calfce:Action.TargetWithoutContext="{Binding}"

to tableview, everything is ok. So whole part of view looks like:

<dxg:GridControl.View>
                <dxg:TableView Name="TableView1"
                   NavigationStyle="Cell"                               
                   AllowEditing="False"
                   AlternateRowBackground="{StaticResource EvenRowBrush}"
                   AlternationCount="2"
                   BestFitArea="All"
                   BestFitMode="VisibleRows"
                   AllowBestFit="True"
                   AllowResizing="True"                               
                   PrintAutoWidth="True"
                   CellValueChanging="TableView1_OnCellValueChanging"
                   ShowIndicator="False"
                   calfce:Action.TargetWithoutContext="{Binding}"
                   >
                    <dxg:TableView.RowCellMenuCustomizations>
                        <dxb:BarButtonItem Content="Export Values"                                              
                               calfce:Message.Attach="[Event ItemClick] = [Action ExportValues()]" />
                    </dxg:TableView.RowCellMenuCustomizations>
                </dxg:TableView>
            </dxg:GridControl.View>

I’m not sure if it’s correct way, but it works :)

D.

Marked as answer by pjenei on 8/26/2014 at 1:13 PM
Aug 26, 2014 at 9:13 PM
Hi David,

Thanks for sharing your solution, I'm sure it'll be helpful for others, too.

Regards,
Peter