wpf-grid 相关问题


将值从用户控件传递到同一用户控件wpf c#中的另一个?

我有四个用户控件,我尝试将值从用户控件传递到另一个用户控件,这些用户控件存在于同一个用户控件中。 这个 xml 主页面 ` 我有四个用户控件,我尝试将值从用户控件传递到另一个用户控件,这些用户控件存在于同一个用户控件中。 这个 xml 主页面 ` <Grid> <StackPanel Background="#FFF"> <local:mwidget x:Name="mwidget" Loaded="UserControl1_Loaded"/> <local:addemploy x:Name="addemploy" Visibility="Hidden"/> <local:editemploy x:Name="editemploy" Visibility="Hidden" /> </StackPanel> </Grid>` 还有这个代码 ` private void UserControl1_Loaded(object sender, RoutedEventArgs e) { mwidget.ShowUserControl2Requested += OnShowUserControl2Requested; addemploy.ShowUserControl1Requested += OnShowUserControl1Requested; editemploy.ShowUserControl1Requestedd += ShowUserControl1Requestedd; mwidget.ShowUserControl2Requestedd += ShowUserControl1Requesteddd; } private void OnShowUserControl2Requested(object sender, EventArgs e) { addemploy.Visibility = Visibility.Visible; mwidget.Visibility = Visibility.Collapsed; } private void OnShowUserControl1Requested(object sender, EventArgs e) { mwidget.Visibility = Visibility.Visible; addemploy.Visibility = Visibility.Collapsed; } private void ShowUserControl1Requestedd(object sender, EventArgs e) { mwidget.Visibility = Visibility.Visible; editemploy.Visibility = Visibility.Collapsed; } private void ShowUserControl1Requesteddd(object sender, EventArgs e) { editemploy.Visibility = Visibility.Visible; mwidget.Visibility = Visibility.Collapsed; }` 这个代码mwidget ` public partial class mwidget : UserControl { public event EventHandler ShowUserControl2Requested; public event EventHandler ShowUserControl2Requestedd; public mwidget() { InitializeComponent(); } private void add_employ(object sender, RoutedEventArgs e) { ShowUserControl2Requested?.Invoke(this, EventArgs.Empty); } private void edit_employ(object sender, System.Windows.RoutedEventArgs e) { ShowUserControl2Requestedd?.Invoke(this, EventArgs.Empty); } }` 所以我想将值从 mwidget 传递到 editemploy,我尝试了一些解决方案,但不起作用 您需要在 mwidget 和 editemploy 中创建 DependencyPropertys 并将它们相互绑定。 (注意:在下面的示例中,我使用了 OneWayToSource。这可以防止 editemploy 更改 mwidget 中的值。如果您不想这样做,请将其更改为 TwoWay。) m小部件: public static readonly DependencyProperty MyValueProperty = DependencyProperty.Register( nameof(MyValue), typeof(bool), typeof(mwidget)); public bool MyValue { get => (bool)GetValue(MyValueProperty); set => SetValue(MyValueProperty, value); } 编辑雇佣: public static readonly DependencyProperty MyPassedValueProperty = DependencyProperty.Register( nameof(MyPassedValue), typeof(bool), typeof(editemploy)); public bool MyPassedValue { get => (bool)GetValue(MyPassedValueProperty); set => SetValue(MyPassedValueProperty, value); } xaml: <local:mwidget x:Name="mwidget" Loaded="UserControl1_Loaded"/> <local:addemploy x:Name="addemploy" Visibility="Hidden"/> <local:editemploy x:Name="editemploy" Visibility="Hidden" MyPassedValue="{Binding ElementName=mwidget, Path=MyValue, Mode=OneWayToSource}" />


创建 WPF 属性网格?

如果我想在 WPF 中创建自己的属性网格控件,我该从哪里开始寻找?


列的 maxWidth 无法使用 ag-grid 中的 autoAutoSize 函数调整大小

我正在尝试将 autosizecolumns 功能与 AG-Grid 和 Angular 框架一起应用。当函数执行时,列将默认采用内容的宽度。因此我为


React 中 Tailwind 动态类值编译的问题[重复]

我目前在尝试基于 Tailwind CSS 中动态生成的网格大小变量创建网格时遇到问题。当我使用变量设置 grid-template-rows 和 grid-template-co...


如何制作wpf倒计时器?

我想创建 wpf 倒数计时器,将结果显示为 hh:mm:ss 到文本框中,我将感谢任何人的帮助。


如何在 WPF 应用程序中生成 FlowDocument 的“打印预览”?

我的各种WPF应用程序显示FlowDocument。我可以使用打印 WPF FlowDocument 的答案中描述的方法来打印它们。 现在我想添加一个“打印预览”


CSS Grid 使页面自动滚动

我一直在论坛上寻找解决这个问题的方法,我能找到的最接近的就是这个。但似乎没有解决办法。 我有一个 CSS 网格,它是 grid-template-columns: Repeat(auto-fill,...


如何将 WPF 应用迁移到 Blazor Hybrid?

我正在研究是否可以通过工具的帮助或以尽可能有效的方式将 WPF 应用程序迁移到 Blazor Hybrid。我需要迁移的应用程序是一个较旧的 WPF 应用程序,它...


在 Angular 15 升级中遇到加载器解析 ag-grid/angular.css 文件的问题

我在将 Angular 14 升级到 15 时遇到此构建错误。 我尝试添加 css 加载器,但没有用 ./node_modules/@ag-grid-community/styles/ag-grid.css?ngGlobalStyle:1:0 - 错误:模块解析失败...


在 MUI Data Grid v6 中更新另一个单元格时,如何在编辑模式下更新一个单元格?

我正在使用 MUI Data Grid v6 组件并利用其内置的 CRUD 编辑功能。我有多个列,所有列都可以编辑。在我的“类别&...”列中选择新值后


如何在 WindowStyle=None 的情况下删除 WPF 窗口顶部的白色条带?

是否可以在 Window Style=None 的情况下删除 WPF 窗口顶部的白色条带。 XAML 和 Window 如屏幕截图所示:


角度同步融合网格过滤

如何在 Syncfusion Grid 中过滤时禁用自动完成功能 我试过这个: 动作开始(参数){ if (args.requestType === '过滤' && args.currentFilterObject.value == null) { ...


使用 C# 在 WPF 类之间传递数据

我正在使用 C# 开发一个 WPF 项目,我需要在不同的类之间传递数据(特别是 ID)。我的设置包括一个 MainWindow、一个 PatientTemplate(一个 ResourceDictionary)和一个


ChromeDriver 在 WPF 应用程序中启动方式不同

如果我运行控制台项目,它会在当前版本上运行 启动 ChromeDriver 120.0.6099.109 但如果我的项目类型是 WPF,则: 启动 ChromeDriver 85.0.4183.87 我收到了e的消息...


将 4 个 div 级联排列为 4 列

我需要排列 4 个层叠的 div,看起来像是 4 列。 这是我的html结构(我无法修改它) 1111 我需要排列 4 个层叠的 div,看起来像是 4 列。 这是我的html结构(我无法修改它) <div class="col1"> 1111 <div class="col2"> 2222 <div class="col3"> 3333 <div class="col4"> 4444 </div> </div> </div> </div> 我需要它在使用时看起来像: display: grid; grid-template-columns: repeat(4, minmax(200px, 1fr)); 我也尝试过 grid-template-areas 但没有达到预期的结果。 好的,所以您需要容器是网格容器,然后元素都属于相同的子级别(即它们都需要属于相同的子元素)。因此你需要重构你的 html 来解决这个问题。这里有一个有用的链接,可以帮助您快速了解如何使用 css 网格。话虽如此,这里有一个 html/css 示例演示了您想要实现的目标。希望这可以帮助您有一个良好的开端。请注意,此示例使用您的值,并将强制每列至少为 200 像素(您显然可以根据您的用例进行更改)。 .grid-container{ display: grid; grid-template-columns: repeat(4, minmax(200px, 1fr)); } <div class="grid-container"> <div class="col1"> 1111 </div> <div class="col2"> 2222 </div> <div class="col3"> 3333 </div> <div class="col4"> 4444 </div> </div>


wpf 属性网格

我的 WPF 应用程序需要一个 PropertyGrid。经过大量搜索后我发现了这一点。 当我将 PropertyGrid 添加到表单并运行它时,我已经添加了程序集(exe 文件),但我在其中看不到它...


WPF - 部署问题 - 错误模块名称:KERNELBASE.dll

我正在尝试安装并运行我的第一个 WPF 应用程序,但遇到了一些问题。我已经构建了一个安装项目,一切似乎都安装正确,我所有的第三方 dll 都已复制


在WPF中当我尝试使用CTRL+TAB切换选项卡时

在 WPF 中,当我尝试使用 CTRL+TAB 切换选项卡时,它可以正常工作,但是如果选项卡位于父选项卡内,那么它将切换到子选项卡,只需要移动父选项卡? 我已经尝试过...


在 AgGrid 中显示组行的单元格值

我正在与 Ag-Grid 企业合作并使用 rowModelType 作为服务器端 我只想显示组行上第二列和第三列的一些自定义值(以红线标记)。 我有检查...


Selenium Grid 未检测到 Docker yaml 文件中的集成

我正在尝试为我的投资组合构建一个自动化测试项目。但我面临着同样的问题。我创建了一个 Docker YAML 文件来编写配置以在 chrome 和


无法在从 WPF 应用程序使用的 WCF 应用程序中调用 ApplyClientBehavior 方法

无法点击ApplyClientBehavior方法 使用 System.ServiceModel.Description; 命名空间 Utils.CMSAuth { 公共类 AuthorizationHeaderEndpointBehavior :IEndpointBehavior { 公开


MUI X DataGrid 在分页结果时仅显示一行

我正在使用 MUI X Data Grid v5 和 Tanstack React Query v4 我正在尝试在我的 Datagrid 组件上使用分页,当页面最初加载时,它会按预期正常获取并加载网格。


C# wpf Datagrid 内容对齐中心通过代码

我生成一个数据网格并希望将内容居中。 这是我的代码: DataGrid 表 = new DataGrid(); tabelle.ItemsSource = dt.DefaultView; 表格.RowHeight = 50; tabelle.VerticalContentAlig...


为什么 File.ReadAllLinesAsync() 会阻塞 UI 线程?

这是我的代码。读取文件行的 WPF 按钮的事件处理程序: private async void Button_OnClick(对象发送者, RoutedEventArgs e) { Button.Content = "正在加载..."; 变种


Powershell 异步

我正在使用 powershell 和 wpf 构建一个 GUI。我想在工具运行时更改按钮的内容。但当其他命令完成后它就发生了变化。我尝试启动


ALV GRID 不会根据值表检查输入,并且不显示匹配代码

我创建了一个包含 5 个字段的自定义表格: MANDT:数据元素 MANDT VBELN:数据元素 VBELN_VA POSNR:数据元素 POSNR_VA EXT_ID:自定义数据元素 VALUE:自定义数据元素 我已经定义了


WPF ToggleButton XAML 样式

我有两个切换按钮,我正在尝试组合它们 - 有点。所以第一个按钮根据 IsChecked 是 true 还是 false 来切换图像,但是这个按钮周围有一个边框......


使用 GetKeyNameText 和特殊键

我已经为WPF编写了一个热键控件,并且想要向用户显示友好的名称。为此,我使用 GetKeyNameText。 然而,例如当使用 Key.MediaNextTrack 作为输入时,GetKeyNameText 重新...


在 C# 中连接到 Basler 相机

我想使用 C# 连接到我的 Basler ace acA1440-73gm 相机。 我将在 .NET7.0 中的 WPF 应用程序中使用它。 要下载哪些 Nuget 包以及如何连接到相机? 我已经安装了...


在代码隐藏中绑定到 DataTable 时,DataGrid 会部分更新

我有一个 WPF 窗口,其中有一个 DataGrid 作为其子窗口之一。 DataGrid 中的列数仅在运行时确定。以下是我的 window.xaml 文件中 DataGrid 的代码: <


EF Core 脚手架数据和属性已更改

我有一个 WPF 应用程序(MVVM Toolkit),其数据模型是使用数据库中的 EFcore 工具搭建的。一个特定类的最终模型如下所示: 公共部分B类...


无法加载DLL“找不到模块HRESULT:0x8007007E”

我有 C# WPF 应用程序,其中使用了 C++ DLL 库。当我构建项目时,它会成功构建,并且所有 DLL 和 exe 都存储在 bin/(Platform) eg(bin/Debug) 文件夹中。 现在如果我...


使用 mage.exe 自动进行扩展验证 (EV) 代码签名

我尝试使用金雅拓存储在 HSM 上的 EV 证书来签署 WPF ClickOnce 应用程序。我配置了持续部署 (CD),并且希望无需用户交互即可自动签名,...


使用WPF + XAML Syncfusion.SfGrid.WPF组合表格中单元格的问题

我有一个问题3天都无法处理。听起来很简单,但事实上却复杂得多。我有一个应用程序,可以从 Excel 文件中获取数据并存储它...


有没有办法结束webview2的异步截屏?

我将在wpf应用程序中使用webview2进行视频聊天。 但是,由于 webview2 是异步运行的,因此即使窗口关闭,它也会识别出用户没有离开服务器。 我只是...


如何使用 WPF 将文本换行到标签中?

我有一个文本框和一个标签。单击按钮后,我执行以下代码: 标签1.内容=文本框1.文本; 我的问题是,如何启用标签的文本换行?可能还有...


log4net 您已尝试将 root 设置为空级别

我有一个WPF应用程序,它使用Log4Net来记录各种信息。该应用程序运行良好,所有内容都按其应有的方式记录。但是,当滚动浏览“输出”窗口时,我


自定义 ListViewItem 控件显示类名称,而常规 ListView 控件显示实际数据

以下是 WPF 应用程序的代码片段,其中我使用 ListView 控件和自定义 ListView 控件,但在 UI 中自定义 ListView 控件显示类名称,其中为 List View


如何在WPF MVVM中显示带有动态列的表格

我有一个对象列表,每个对象都包含用户定义的属性。这些属性的键和值是自由字符串,因此它们在对象之间不一定一致。无论如何,我


System.Text.Json.JsonException:'JSON 值无法转换为 System.Collections.Generic.List`1

我正在尝试构建一个 WPF 应用程序以将假日详细信息存储在 SQL Server 数据库中。我向最终用户请求地址并尝试对地址进行地理编码。为此,我发出一个网络请求...


如何禁用列表框中的项目,即使它在 WPF 中具有多选模式?

我正在努力在列表框中创建一个标题,该标题将变成灰色,并且其中有一个冒号,而其余条目(列表框项目)将为黑色。 我想做的是如果...


是否可以在 WPF / Touch 应用程序中弹出一个忽略 MenuDropAlignment 的窗口?

作为一点背景知识 - Windows 有一个针对触摸/平板电脑的功能,它可以根据您的“惯用手”移动弹出窗口/菜单的位置(以防止菜单出现在您的手下)。


在 WPF C# 中根据数据网格中的另一个组合框过滤 DataGrid 中的组合框?

在我的示例中,我在数据网格中有3个组合框,分别显示国家、省份和地区。我如何以这种方式按国家过滤省份和按省份过滤地区


WPF:为什么绑定模式OneWay没有调用回调函数?

我创建了一个带有一些属性的自定义控件,所有这些似乎都正常工作。 但经过一些测试,我发现了一种我不明白的奇怪行为。当我在 OneWay mod 中绑定属性时...


为什么 Android 上两个组件之间的切换速度如此之慢?

我正在使用 Expo/React Native/Typescript 构建一个类似于填字游戏的小型拼图应用程序。 这是 PuzzleMain 组件的精简版本: const PuzzleMain:React.FC 我正在使用 Expo/React Native/Typescript 构建一个类似于填字游戏的小型拼图应用程序。 这是 PuzzleMain 组件的精简版本: const PuzzleMain: React.FC<PuzzleMainProps> = ({ navigation }) => { let puzzle: AcrosticPuzzleData = parseAcrosticPuzzle(PUZZLE_TEXT); const grid = <PuzzleGrid puzzle={puzzle} />; const clueView = <PuzzleCluesView puzzle={puzzle} />; const [index, setIndex] = React.useState(0); return <View style={styles.container}> {index == 0 ? grid : clueView} <View style={styles.keyboardContainer}> <Button onPress={() => setIndex(index == 1 ? 0 : 1)} title={"See " + routes[index == 0 ? "Grid" : "Clues"].key} /> <Keyboard /> </View> </View>; } 总结一下,有“网格”组件和“线索”组件,并通过按钮在它们之间进行切换。 毫不夸张地说,在我用来测试的 Pixel 5 上点击此按钮大约需要 3 秒的时间才能进行更改。我在这里做错了什么?使用Expo在网络上打开这个,它立即发生,所以可能它是Android特有的? 我尝试过的事情: 记住 PuzzleGrid 和 PuzzleCluesView 组件(const PuzzleGrid: React.FC<Props> = memo(({ puzzle }) ...。这基本上没有什么区别。我检查过,在我为备忘录功能制作的自定义拼图比较器中没有打印任何内容,所以我认为它没有重新渲染。 改用 TabView 在组件之间滑动 - 这有效!但说实话,我真的更喜欢两者兼得,而且当我将其合并到 TabView 实现中时,按钮同样很慢。 使用 npx expo start --no-dev 并仅构建一个 apk 并安装 - 这使得速度更快,但仍然可能需要整整一两秒,这太慢了。 正如我所看到的,您正在执行条件渲染,因此每次条件更改时,整个组件都会被创建为新组件。这种方法会使渲染速度变慢,具体取决于组件的重量。 为什么备忘录不起作用? Memo 是一种优化技术,并不能保证性能提升。 现在,提升加载速度 内部优化PuzzleGrid和PuzzleCluesView,比如每个可以接收重复道具的子组件都会被memo覆盖,重型物品会异步加载,使用loader。 使用 InteractionManager 提高加载速度,并帮助显示加载程序而不冻结 UI。 不要卸载组件,而是重叠它们并使用可见性,因为可见性不会卸载组件 而不仅仅是 {index == 0 ? grid : clueView}你可以尝试类似的事情 <View> {grid} <View style={{ // Add height and other required props to make it visible position: 'absolute', visibility: index == 0 ? 'hidden' : 'visible', }}> {clueView} </View> </View>


C# - 尝试将文件路径添加到 NavigateUri 中,每个用户可能会有所不同

我正在尝试将文件路径超链接添加到我的 WPF 项目中,该项目的一部分可能对每个用户来说都不同。我知道一个注册表位置,我可以在其中获取...的第一部分...


在 WPF MVVM 应用程序中使用依赖项注入处理对用户可选择文件的数据访问的正确方法是什么?

考虑以下情况: MVVM 桌面 GUI 应用程序,用户可以在其中创建/编辑“项目”。 想象一个像 Visual Studio 解决方案这样的项目:它是一个文件(当前是......


Pinia 对象在 Vue 中的 foreach 后失去反应性

我有这个嵌套的foreach BalanceItemList.vue ... 我有这个嵌套的 foreach BalanceItemList.vue <template> <div v-for="category in categoryItemsStore.balanceCategories" :key="category.id" class="mt-5"> <div class="border-black border-b bg-gray-200"> <span class="font-bold w-full">{{ category.name }}</span> </div> <div v-for="balanceItem in category.balance_items" :key="balanceItem.id"> {{ balanceItem.total = 500 }} <balance-item :balance-item="balanceItem" @update-balance-item="update"/> </div> <div> <balance-item-create :category="category.id" @create-balance-item="update"/> </div> <div v-if="categoryItemsStore.totals[category.id]" class="grid grid-cols-4-b t-2 ml-2"> <div :class="category.is_positive ? '': 'text-red-600' " class="col-start-4 border-t-2 border-black font-bold"> &euro;{{ categoryItemsStore.totals[category.id].total }} </div> </div> </div> </template> 我像这样检查了“balanceItem”的反应性 {{ balanceItem.total = 500 }} 它在商店中更新,但随后我有了我的平衡项目组件: BalanceItem.vue <script setup> import {reactive} from "vue"; import {useForm} from "@inertiajs/vue3"; import NumberInput from "@/Components/NumberInput.vue"; import {UseCategoryItemsStore} from "@/Stores/UseCategoryItemsStore.js"; const categoryItemStore = UseCategoryItemsStore() const props = defineProps({balanceItem: Object, errors: Object}) let item = reactive(props.balanceItem); const form = useForm(item); const emit = defineEmits(['update-balance-item']) const submit = () => { form.post(route('balance-item.update'), { preserveScroll: true, onSuccess: () => { props.balanceItem.total = 500 categoryItemStore.updateBalanceItemsTotals(form) emit('update-balance-item') } }) } </script> <template> <form @submit.prevent="submit"> <div class="grid grid-cols-4-b"> <span>{{ item.name }}</span> <NumberInput v-model="form.count" autofocus class=" mr-4 mt-1 block" type="number" @update:model-value="submit" /> <div :class="item.item_category.is_positive ? '' : 'text-red-600'" class="flex place-items-center"> <div class="pt-1 mr-1">&euro;</div> <NumberInput v-model="form.amount" :class="form.errors.amount ? 'border-red-600' : ''" autofocus class="mt-1 mr-4 w-5/6" type="text" @update:model-value="submit" /> </div> <div :class="item.item_category.is_positive ? '' : 'text-red-600'" class="flex place-items-center"> <div class="pt-1 mr-1 w-5/6">&euro;</div> <NumberInput v-model="form.total" autofocus class="mt-1 block" disabled style="max-width: 95%" type="text" /> </div> </div> </form> </template> 这是我测试反应性的商店。如果我增加输入的数字,则项目的计数保持不变 UseCategoryItemsStore.js import {defineStore} from "pinia"; import {ref} from "vue"; export const UseCategoryItemsStore = defineStore('UseCategoryItemsStore', () => { const balanceCategories = ref([]) const totals = ref([]) function getBalanceItems() { axios.get(route('balance-item.index')).then((response) => { balanceCategories.value = response.data // console.log(balanceCategories.value) }) } function getTotals() { axios.get(route('balance-item.totals')).then((response) => totals.value = response.data) } function getData() { getTotals() getBalanceItems() } function updateBalanceItemsTotals(selectedItem) { balanceCategories.value.forEach((category) => { category.balance_items.forEach((item) => { if (item.id === selectedItem.id) { // item.total = item.count * item.amount console.log(item) } }) }) } getTotals() getBalanceItems() return {balanceCategories, totals, getBalanceItems, getTotals, getData, updateBalanceItemsTotals} }) 在此测试中,我执行“props.balanceItem.total = 500”。但如果我检查商店,它不会更新。看来将“balanceItem”分配给一个道具会失去与我的 Pinia 商店的反应性。我可以使用“form.total = form.count * form.amount”手动更新我的表单,但这对我来说似乎很老套,我想使用 Pinia 商店的反应性。我考虑过根据“BalanceItem”获取 Pina 项目,但这似乎也很棘手。谁知道为什么失去反应性? 我有laravel 10.39、vue3.2.41和pinia 2.1.17惯性0.6.11。到目前为止我知道的所有最新版本。 我像这样更新我的表格和商店: <script setup> import {useForm} from "@inertiajs/vue3"; import NumberInput from "@/Components/NumberInput.vue"; import {UseCategoryItemsStore} from "@/Stores/UseCategoryItemsStore.js"; const categoryItemStore = UseCategoryItemsStore() const props = defineProps({balanceItem: Object, errors: Object}) let item = categoryItemStore.getItemById(props.balanceItem); let form = useForm(item); const emit = defineEmits(['update-balance-item']) const submit = () => { form.post(route('balance-item.update'), { preserveScroll: true, onSuccess: () => { item = categoryItemStore.updateItem(form) form = useForm(item) emit('update-balance-item') } }) } </script> 我将此功能添加到我的商店: import {defineStore} from "pinia"; import {ref} from "vue"; export const UseCategoryItemsStore = defineStore('UseCategoryItemsStore', () => { const balanceCategories = ref([]) const totals = ref([]) function getBalanceItems() { axios.get(route('balance-item.index')).then((response) => { balanceCategories.value = response.data // console.log(balanceCategories.value) }) } function getItemById(item) { let category = balanceCategories.value.find((category) => { return category.id === item.item_category_id }) return category.balance_items.find((item_from_store) => { return item_from_store.id === item.id }) } function updateItem(form) { const item = getItemById(form) item.count = form.count item.amount = form.amount item.total = item.count * item.amount return item } function getTotals() { axios.get(route('balance-item.totals')).then((response) => totals.value = response.data) } function getData() { getTotals() getBalanceItems() } getTotals() getBalanceItems() return {balanceCategories, totals, getBalanceItems, getTotals, getData, getItemById, updateItem} }) 假设如果帖子获得 200,我的表单值可用于更新商店和更新表单。这是我能想到的最好的


.NET MAUI、ios UseSafeArea 不工作 StackLayout、VerticalStackLayout 和 Grid

<?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Test.Views.Activities.ActivityMapList" xmlns:maps="clr-namespace:Microsoft.Maui.Controls.Maps;assembly=Microsoft.Maui.Controls.Maps" xmlns:sensors="clr-namespace:Microsoft.Maui.Devices.Sensors;assembly=Microsoft.Maui.Essentials" xmlns:ios="clr-namespace:Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific;assembly=Microsoft.Maui.Controls" ios:Page.UseSafeArea="False" Shell.NavBarIsVisible="False" Style="{StaticResource Key=DefaultPage}"> <ContentPage.Content> <StackLayout> <maps:Map VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"> <x:Arguments> <MapSpan> <x:Arguments> <sensors:Location> <x:Arguments> <x:Double>36.9628066</x:Double> <x:Double>-122.0194722</x:Double> </x:Arguments> </sensors:Location> <x:Double>0.01</x:Double> <x:Double>0.01</x:Double> </x:Arguments> </MapSpan> </x:Arguments> </maps:Map> </StackLayout> </ContentPage.Content> </ContentPage> StackLayout 或 Grid 内的地图控件,iOS 的 SafeArea 为 false,如图所示。 你有什么解决办法吗? 我需要在地图上使用网格或堆栈布局 默认情况下.NET MAUI 将考虑安全区域。所以使用特定于平台的UseSafeArea就是禁用安全区域。目前,将 UseSafeArea 设置为 false 不会改变行为(尽管应该如此),这是一个错误。另请参阅 MAUI github 上的问题:https://github.com/dotnet/maui/issues/5856 您还可以设置 IgnoreSafeArea 属性来实现相同的目的。但是,它不再在 .NET 7 中工作,请参阅以下问题:https://github.com/dotnet/maui/issues/12823 要解决您的问题,您需要将 IgnoreSafeArea="True" 添加到您的 Grid 或 StackLayout 并将 ios:Page.UseSafeArea="False" 添加到您的页面。这应该不是必需的,但这是对我有用的解决方法。 有关在 iOS 上禁用安全区域的文档可以在此处找到:https://learn.microsoft.com/en-us/dotnet/maui/ios/platform-specifics/page-safe-area-layout?view=net-毛伊岛-7.0 您可以设置 Page Padding 值来实现。在OnAppearing方法中,设置页面的safeInsets,如下代码: protected override void OnAppearing() { base.OnAppearing(); DeviceSafeInsetsService d = new DeviceSafeInsetsService(); double topArea = d.GetSafeAreaTop(); double bottomArea = d.GetSafeAreaBottom(); var safeInsets = On<iOS>().SafeAreaInsets(); safeInsets.Top = -topArea; safeInsets.Bottom = -bottomArea; Padding = safeInsets; } 要获取 topArea 和 bottomArea 值,您应该编写平台代码。答案末尾附有有关此内容的更详细教程。 首先你可以在Project文件夹中生成一个新的类文件并将其更改为部分类。生成两个部分方法。 public partial class DeviceSafeInsetsService { public partial double GetSafeAreaTop(); public partial double GetSafeAreaBottom(); } 然后在iOS平台生成部分文件并实现。该文件位于 Project/Platform/iOS 文件夹中,我想提一下的是,该文件是一个部分文件,因此命名空间应与上面的文件相同。生成此文件时,请删除命名空间中的 .Platforms.iOS 后缀。 public partial class DeviceSafeInsetsService { public partial double GetSafeAreaBottom() { if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0)) { UIWindow window = UIApplication.SharedApplication.Delegate.GetWindow(); var bottomPadding = window.SafeAreaInsets.Bottom; return bottomPadding; } return 0; } public partial double GetSafeAreaTop() { if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0)) { UIWindow window = UIApplication.SharedApplication.Delegate.GetWindow(); var TopPadding = window.SafeAreaInsets.Top; return TopPadding; } return 0; } } 更多信息,您可以参考如何在.NET MAUI中编写特定于平台的代码和MauiPlatformCode示例代码 希望它对你有用。


.NET MAUI:自定义Shell TitleView并绑定到当前页面标题

我想用我自己的自定义布局替换默认的 Shell 标头,如下所示: 我想用我自己的自定义布局替换默认的 Shell 标头,如下所示: <?xml version="1.0" encoding="UTF-8" ?> <Shell x:Class="MyNamespace.App.AppShell" xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:MyNamespace.App" xmlns:pages="clr-namespace:MyNamespace.App.Pages" BindingContext="{x:Static local:MainView.Instance}" Shell.FlyoutBehavior="{Binding ShellFlyoutType}" x:Name="shellMain"> <Shell.TitleView> <Grid ColumnDefinitions="*,200"> <Label BindingContext="{x:Reference shellMain}" Text="{Binding Path=CurrentPage.Title, Mode=OneWay}" FontSize="Large" TextColor="White" /> <ActivityIndicator IsRunning="{Binding IsBusy}" Color="Orange" Grid.Column="1" HorizontalOptions="End" /> </Grid> </Shell.TitleView> <ShellContent Title=" Login" ContentTemplate="{DataTemplate local:MainPage}" Route="login" FlyoutItemIsVisible="False" /> <ShellContent Title="Dashboard" ContentTemplate="{DataTemplate pages:DashboardPage}" Route="dashboard" /> </Shell> 我无法绑定当前页面标题。 我的 AppShell.xaml Shell 声明如下 <Shell ... x:Name="shellMain"> 作为替代方案,您可以在 OnNaviged 方法中设置 titleview : 在 AppShell.xaml 中,定义标签的名称 <Shell.TitleView> <Grid ColumnDefinitions="*,200"> <Label BindingContext="{x:Reference shellMain}" x:Name="mylabel" FontSize="Large" TextColor="White" /> <ActivityIndicator IsRunning="{Binding IsBusy}" Color="Orange" Grid.Column="1" HorizontalOptions="End" /> </Grid> </Shell.TitleView> 在AppShell.xaml.cs中,重写OnNaviged方法,获取当前项目 protected override void OnNavigated(ShellNavigatedEventArgs args) { base.OnNavigated(args); var shellItem = Shell.Current?.CurrentItem; string title = shellItem?.Title; int iterationCount = 0; while (shellItem != null && title == null) { title = shellItem.Title; shellItem = shellItem.CurrentItem; if (iterationCount > 10) break; // max nesting reached iterationCount++; } myLabel.Text = title; } 希望它对你有用。 我正在尝试同样的方法来修改 TitleView 的外观。它可以在 iOS 上运行,尽管那里还有另一个错误。但在 Android 上我遇到了同样的问题。在前进导航中,它会更新标题,但当您按后退按钮时,标题不会更新。我已经打开了一个问题并添加了一个存储库。 https://github.com/dotnet/maui/issues/12416#issuecomment-1372627514 还有其他方法可以修改TitleView的外观吗? 我使用视图模型开发了这个解决方法,主要不是为了提供 MVVM 解决方案,而是因为其他建议的答案对我不起作用。 (我怀疑 Liqun Shen 2 月 15 日针对他自己的问题的评论中的建议会起作用。但我没有注意到这一点,直到我自己修复)。 当前页面的标题保存在可由 shell 的视图模型和每个内容页面的视图模型访问的类中: public class ServiceHelper { private static ServiceHelper? _default; public static ServiceHelper Default => _default ??= new ServiceHelper(); internal string CurrentPageTitle { get; set; } = string.Empty; } shell 中每个内容页面的视图模型提供其页面标题。为了促进这一点,大部分工作都是由基本视图模型完成的,它们都是从该模型派生而来的: public abstract class ViewModelBase(string title) : ObservableObject { private ServiceHelper? _serviceHelper; public string Title { get; } = title; internal ServiceHelper ServiceHelper { get => _serviceHelper ??= ServiceHelper.Default; set => _serviceHelper = value; // For unit testing. } public virtual void OnAppearing() { ServiceHelper.CurrentPageTitle = Title; } } 每个 shell 内容页面视图模型只需要让其基础视图模型知道它的标题: public class LocationsViewModel : ViewModelBase { public LocationsViewModel() : base("Locations") { } } 每个 shell 内容页面都需要在其视图模型中触发所需的事件响应方法: public partial class LocationsPage : ContentPage { private LocationsViewModel? _viewModel; public LocationsPage() { InitializeComponent(); } private LocationsViewModel ViewModel => _viewModel ??= (LocationsViewModel)BindingContext; protected override void OnAppearing() { base.OnAppearing(); ViewModel.OnAppearing(); } } Shell 的视图模型为标题栏提供当前页面的标题: public class AppShellViewModel() : ViewModelBase(Global.ApplicationTitle) { private string _currentPageTitle = string.Empty; public string CurrentPageTitle { get => _currentPageTitle; set { _currentPageTitle = value; OnPropertyChanged(); } } public void OnNavigated() { CurrentPageTitle = ServiceHelper.CurrentPageTitle; } } Shell 需要在其视图模型中触发所需的事件响应方法: public partial class AppShell : Shell { private AppShellViewModel? _viewModel; public AppShell() { InitializeComponent(); } private AppShellViewModel ViewModel => _viewModel ??= (AppShellViewModel)BindingContext; protected override void OnNavigated(ShellNavigatedEventArgs args) { base.OnNavigated(args); ViewModel.OnNavigated(); } } 最后,Shell 的 XAML 在标题栏/导航栏上显示由 Shell 视图模型提供的当前页面的标题: <Shell.TitleView> <HorizontalStackLayout VerticalOptions="Fill"> <Image Source="falcon_svg_repo_com.png" HeightRequest="50"/> <Label x:Name="CurrentPageTitleLabel" Text="{Binding CurrentPageTitle}" FontSize="24" Margin="10,0" VerticalTextAlignment="Center"/> </HorizontalStackLayout> </Shell.TitleView>


© www.soinside.com 2019 - 2024. All rights reserved.