我想在我的Xamarin应用程序中显示pdf。因此,我创建了一个包含WebView的屏幕。在该webView中,显示我的PDF。但是,当我也想显示“自定义导航”时,问题就来了。 WebView不会显示,而我只能看到白色的空白屏幕。这是我的xcml:
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:AAAIDApp.Views.CustomControls"
xmlns:translate="clr-namespace:AAAIDApp.Extensions"
x:Class="AAAIDApp.Views.pdfjsPage"
xmlns:renders="clr-namespace:AAAIDApp.Renders"
NavigationPage.HasNavigationBar="False"
>
<ContentPage.Content>
<Grid Padding="0" Margin="0" VerticalOptions="FillAndExpand">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<local:CustomNavigation Grid.Row="0" Grid.Column="0" x:Name="CustomNavigationListPDF" CloseAction="CustomNavigation_CloseAction" />
<StackLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Grid.Row="1" Grid.Column="0">
<Grid IsVisible="False" Margin="20,10,20,10" ColumnSpacing="10" >
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Label x:Name="TXTBck" Text="" FontSize="28" FontFamily="{StaticResource FontAwesome}" TextColor="{x:StaticResource IconBackColor}" Grid.Column="0" VerticalOptions="Center" HorizontalOptions="Center">
<Label.GestureRecognizers>
<TapGestureRecognizer Tapped="Back_Tapped"/>
</Label.GestureRecognizers>
</Label>
<Label x:Name="TXTIcons_Meeting" IsVisible="False" Text="" FontFamily="{StaticResource FontAwesome}" FontSize="24" TextColor="{StaticResource FontTitleIconColor}" Grid.Column="1" VerticalOptions="Center" >
</Label>
<Label x:Name="TextTitle" TextColor="{StaticResource LightGrayColor}" FontSize="Large" Grid.Column="2" VerticalOptions="Center" />
</Grid>
<!--<Grid>
<Label x:Name="Dowenload" Text="Download PDF" TextColor="Blue" HorizontalOptions="Center" VerticalOptions="Center">
<Label.GestureRecognizers>
<TapGestureRecognizer Tapped="Download_PDF"/>
</Label.GestureRecognizers>
</Label>
</Grid>-->
<Grid>
<local:PdfWebView x:Name="PdfView" HeightRequets = "1000" WidthRequest= "1000" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" ></local:PdfWebView>
</Grid>
</StackLayout>
</Grid>
</ContentPage.Content>
</ContentPage>
和我的.cs文件是这样的:
public pdfjsPage()
{
InitializeComponent();
CustomNavigationListPDF.PageTitle = "PDF";
CustomNavigationListPDF.PageIcon = "\uf073";
}
PdfWebView为空:
{
public class PdfWebView : WebView
{
}
}
CustomNavigation看起来像这样:
<?xml version="1.0" encoding="UTF-8"?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="AAAIDApp.Views.CustomControls.CustomNavigation">
<ContentView.Content>
<StackLayout HorizontalOptions="FillAndExpand" Spacing="0" >
<Grid Padding="20,10,20,0" Margin="0" ColumnSpacing="10" HorizontalOptions="FillAndExpand">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Frame BackgroundColor="Transparent" HasShadow="False" Grid.Row="0" Grid.Column="0" Padding="0" Margin="0" WidthRequest="40" HeightRequest="30" >
<Label Text="" x:Name="LBLBack" FontSize="30" TextColor="#3d3d3d" VerticalOptions="Center" HorizontalOptions="Start" FontFamily="{StaticResource FontAwesome}">
</Label>
<Frame.GestureRecognizers>
<TapGestureRecognizer Tapped="BackLabel_Tapped"/>
</Frame.GestureRecognizers>
</Frame>
<!--<BoxView BackgroundColor="Transparent" Grid.Column="0" Grid.ColumnSpan="2" >
</BoxView>-->
<Label x:Name="LBLIcon" TextColor="{StaticResource FontTitleIconColor}" FontSize="28" Grid.Row="0" Grid.Column="1" VerticalOptions="Center" FontFamily="{StaticResource FontAwesome}">
</Label>
<StackLayout Grid.Column="2" VerticalOptions="Center">
<Label x:Name="CustomNavTitle" VerticalOptions="Center" VerticalTextAlignment="Center" TextColor="{StaticResource LightGrayColor}" FontSize="Large"/>
</StackLayout>
<Frame BackgroundColor="Transparent" HasShadow="False" Grid.Row="0" Grid.Column="3" Padding="0" Margin="0" WidthRequest="40" HeightRequest="30" >
<Label Text="" FontSize="28" x:Name="btnClose" TextColor="#3d3d3d" HorizontalOptions="End" VerticalOptions="Center" FontFamily="{StaticResource FontAwesome}">
<Label.GestureRecognizers>
<TapGestureRecognizer Tapped="Closed_Tapped"/>
</Label.GestureRecognizers>
</Label>
<Frame.GestureRecognizers>
<TapGestureRecognizer Tapped="BackLabel_Tapped"/>
</Frame.GestureRecognizers>
</Frame>
</Grid>
<BoxView BackgroundColor="{StaticResource LineColor}" HorizontalOptions="FillAndExpand" HeightRequest="1" Margin="0,5,0,0"/>
</StackLayout>
</ContentView.Content>
</ContentView>
答案 0 :(得分:0)
您可以删除public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_records, container, false);
initRecyclerView(view);
return view;
}
private void initRecyclerView(View view) {
RecyclerView recyclerView = view.findViewById(R.id.recyclerview);
RecyclerViewAdapter adapter = new RecyclerViewAdapter(mNames, getActivity().getApplicationContext(), (RecyclerViewAdapter.OnNoteListener) this);
recyclerView.setAdapter(adapter);
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity().getApplicationContext()));
}
中的Grid
,只需将local:PdfWebView
放在local:PdfWebView
中,它便可以正常运行